2

I am having the following error:

Column count doesn't match value count at row 1

and my code is:

Connection             con=DriverManager.getConnection("jdbc:mysql://127.0.0.1/BFPL","root","[PASSWORD]");
PreparedStatement ps=con.prepareStatement("Insert into User values(?,?,?,?,?,?)");
ps.setString(1,t52.getText());
ps.setString(2,pw2.getText());
ps.setString(3,t53.getText());
ps.setString(4,t54.getText());
ps.setInt(5,100);
ps.setInt(6,11);
ps.executeUpdate();
PreparedStatement ps1=con.prepareStatement("Insert into User_Team values(?,?)");
ps1.setString(1,t52.getText());
ps1.setInt(2,0);
ps1.executeUpdate();
con.close();

in first table user their are 6 columns, and in 2nd table User_team their are 13 columns in which i am inserting just 2 values from which 1st value is primary key.

4

2 回答 2

4

如果您没有在表的所有列中插入,那么您必须像这样在插入查询中命名要插入的列

Insert into User_Team (col1, col4) values(?,?)

想一想——数据库引擎应该如何知道这些值属于哪些列?

于 2013-01-07T22:53:55.393 回答
2
PreparedStatement ps1=con.prepareStatement("Insert into User_Team (col_name1, col_name2) values(?,?)");
于 2013-01-07T22:54:43.593 回答