我写的这个数据库程序,在程序中添加的客户基本信息,没运行一次程序都增加一次,这是为什么啊??
就是每运行一次程序都添加一次 张三 李四 王五的信息,三个三个的添加,我修改一个客户的信息是也是他们三个一起修改,就是三个三个的修改,改一个变三个,是不是我添加数据库信息的位置不对啊?大家给我挑挑毛病吧。
源程序1:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import
java.sql.SQLException;
import java.sql.Statement;
public class Database {
public static Connection cn;
public static Statement st;
public static ResultSet rs;
public static boolean joinDB() {
boolean joinFlag;
try {
joinFlag = true;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
cn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=sample","sa","605");
cn.setCatalog("sample");
System.out.println("数据库连接成功");
st = cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
st.execute("INSERT INTO Table3 VALUES ('admin','123')");
st.execute("INSERT INTO Clientm VALUES ('张三','男','23')");
st.execute("INSERT INTO Clientm VALUES ('李四','女','25')");
st.execute("INSERT INTO Clientm VALUES ('王五','男','20')");
return joinFlag;
} catch (
SQLException sqlEx) {
System.out.println(sqlEx.getMessage());
joinFlag = false;
return joinFlag;
} catch (
ClassNotFoundException notfoundEX) {
System.out.println(notfoundEX.getMessage());
joinFlag = false;
return joinFlag;
}
}
public static boolean executeSQL(String sqlString) {
boolean executeFlag;
try {
st.execute(sqlString);
executeFlag = true;
} catch (Exception e) {
executeFlag = false;
System.out.println("sql exception:" + e.getMessage());
}
return executeFlag;
}
public static boolean query(String sqlString) {
try {
rs = null;
rs = st.executeQuery(sqlString);
} catch (Exception Ex) {
System.out.println("sql exception:" + Ex);
return false;
}
return true;
}
}
源程序2:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import javax.swing.*;
public class Land
{
public static void main(String[] args)
{
LandFrame frame=new LandFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class LandFrame extends JFrame
{
JFrame jf ;
JLabel labelWelcome = new JLabel("小区车辆管理系统");
JLabel labelName=new JLabel("用户名:");
JLabel labelPassword=new JLabel("密码:");
JTextField textName=new JTextField();
JPasswordField textPassword=new JPasswordField();
JButton buttonEnter=new JButton("登录");
JButton buttoncancel=new JButton("清空");
public LandFrame()
{
jf=this;
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();