ID = s1;
PASSWORD = s2;
NAME = s3;
s1,s2,s3是傳進來的參數,有具體值,但是以
sql = "insert into qq(ID,PASSWORD,NAME) values(ID,PASSWORD,NAME)";
st.executeUpdate(sql);
寫入數據庫,數據庫中的ID,PASSWORD,NAME都是空的,但是
System.out.println(ID);
System.out.println(PASSWORD);
System.out.println(NAME);這樣檢驗ID這些的值又是有的,求問為什麼寫入數據庫就為空了?
zhuce.yon(S1,S2,S3);
public class zhuce {
public static void yon(String s1, String s2, String s3)
{
String ID = null;
String PASSWORD = null;
String NAME = null;
ID = s1;
PASSWORD = s2;
NAME = s3;
Connection con = null;
String sql;
Statement st = null;
try {
con = JDBC.getConnection();
} catch (SQLException e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null,"數據庫連接失敗!","錯誤",2);
e.printStackTrace();
}
try {
System.out.println(ID);
System.out.println(PASSWORD);
System.out.println(NAME);
st = con.createStatement();
} catch (SQLException e) {
// TODO Auto-generated
e.printStackTrace();
}
sql = "insert into qq(ID,PASSWORD,NAME) values(ID,PASSWORD,NAME)";
try {
st.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null,"注冊失敗","錯誤",2);
e.printStackTrace();
}
}
}
解決了,應該用 sql = "insert into qq(id,password,name) values ("+s1+","+s2+","+s3+")";