final String name=tf.getText().trim();
char[] c=tf2.getPassword();
final String pass=new String(c);
final int age=Integer.parseInt(tf5.getText());
final String sex=tf3.getText();
final String xueli=tf4.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "123456");
String sql="insert into user values(?,?,?,?,?)";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, name);
ps.setString(2, pass);
ps.setInt(3, age);
ps.setString(4, xueli);
ps.setString(5, sex);
ps.executeUpdate();
ps.close();
con.close();
有java.sql.SQLException: Column count doesn't match value count at row 1异常
可是我数据库中值就是5个啊 都一一配对的 怎么回事?
高手指点了。
char[] c=tf2.getPassword();
final String pass=new String(c);
final int age=Integer.parseInt(tf5.getText());
final String sex=tf3.getText();
final String xueli=tf4.getText();
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "123456");
String sql="insert into user values(?,?,?,?,?)";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1, name);
ps.setString(2, pass);
ps.setInt(3, age);
ps.setString(4, xueli);
ps.setString(5, sex);
ps.executeUpdate();
ps.close();
con.close();
有java.sql.SQLException: Column count doesn't match value count at row 1异常
可是我数据库中值就是5个啊 都一一配对的 怎么回事?
高手指点了。
2、SQL语句尽量写详细点,如:
insert into userABC values(?,?,?,?,?)
写成:
insert into userABC(c1,c2,c3,c4,c5) values(?,?,?,?,?)
这种对于SQLServer有这个问题
你在网上查查便知道了