String query = "INSERT INTO
用户(
INT ,
FNAME ,
L-NAME ,
岁,
SNAME ,
BNAME ) VALUES ('"+jTextField_FirstName.getText()+"','"+jTextField_LastName.getText()+"',"+jTextField_Age.getText()+",'"+jTextField_SName.getText()+"','"+jTextField_BName.getText()+"')";
这是stacktrace:
java.sql.SQLException: Column count doesn't match value count at row 1 at
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) at
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976) at
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912) at
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530) at
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683) at
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2482) at
com.mysql.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1552)
答案 0 :(得分:3)
您想设置6列int, fname, lname, age, sname, bname
但您只提供5个列值。
再添加一个列值,然后就可以了
答案 1 :(得分:0)
String query = "INSERT INTO users(int, fname, lname, age, sname, bname) VALUES
('"+jTextField_FirstName.getText()+"','"+jTextField_LastName.getText()+"',"
+jTextField_Age.getText()+",'"+jTextField_SName.getText()+"','"
+jTextField_BName.getText()+"')";
根据查询,您要为fname,lname,age,sname,bname插入值, 不是为了你的查询,如下所示为int
设置第一个值String query = "INSERT INTO users(int, fname, lname, age, sname, bname) VALUES
('"+value_for_int+"','"+jTextField_FirstName.getText()+"','"+jTextField_LastName.getText()+"',"
+jTextField_Age.getText()+",'"+jTextField_SName.getText()+"','"
+jTextField_BName.getText()+"')";
答案 2 :(得分:0)
您提供六个 colomuns,如下所示,
INSERT INTOusers(int,fname,lname,age,sname,bname)
但是只提供了五个值,如下所示,
jTextField_FirstName.getText()
jTextField_LastName.getText()
jTextField_Age.getText()
jTextField_SName.getText()
jTextField_BName.getText()
为插入查询中指定的 int 提供一个更多值,然后没有错误!!