java.sql.SQLException:列计数不';不匹配第1行的值计数
我当前在运行程序查询时遇到此错误 java.sql.SQLException:列计数 与第1行的值计数不匹配 但我不知道为什么,我所有的价值观都在那里,而且是一致的。 这是我执行sql语句的代码java.sql.SQLException:列计数不';不匹配第1行的值计数,java,mysql,jdbc,Java,Mysql,Jdbc,我当前在运行程序查询时遇到此错误 java.sql.SQLException:列计数 与第1行的值计数不匹配 但我不知道为什么,我所有的价值观都在那里,而且是一致的。 这是我执行sql语句的代码 c = DriverManager.getConnection( url, username, password ); String selectStatement = "INSERT INTO entry ( id, name, title, note) VALUES (?),(?),(?),(?
c = DriverManager.getConnection( url, username, password );
String selectStatement = "INSERT INTO entry ( id, name, title, note) VALUES (?),(?),(?),(?)";
PreparedStatement prepStmt = (PreparedStatement) c.prepareStatement(selectStatement);
prepStmt.setInt(1, idSeed++);
prepStmt.setString(2, name2);
prepStmt.setString(3, title2);
prepStmt.setString(4, note2);
prepStmt.executeUpdate();
您的SQL语法不正确。一定是
INSERT INTO entry ( id, name, title, note) VALUES (?,?,?,?)
请对您的存在代码进行以下更改 也要保持idSeed的价值
Values标签应该类似于值(?,?,?);你得到正确的输出吗?我对此表示怀疑。我的意思是需要其他更改,而不是插入查询。
String selectStatement = "INSERT INTO entry ( id, name, title, note) VALUES (?,?,?,?)";
PreparedStatement prepStmt = (PreparedStatement) c.prepareStatement(selectStatement);
prepStmt.setInt(1, idSeed); // remove ++ from here, do it in last
prepStmt.setString(2, name2);
prepStmt.setString(3, title2);
prepStmt.setString(4, note2);
prepStmt.executeUpdate();
Notes entry = new Notes(idSeed, name2, title2,note2 ); //now you will get exactly what inserted into DB table
entries.add(entry);
idSeed++; // now increment it, which will reflect into next iteration...