我正在运行程序查询时出现此错误,
java.sql.SQLException:列数 不匹配第1行的值计数
但是我不知道为什么,我所有的价值观都在那里并且匹配起来。 这是我做我的sql语句的代码。
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();
答案 0 :(得分:3)
您的SQL语法不正确。一定是
INSERT INTO entry ( id, name, title, note) VALUES (?,?,?,?)
答案 1 :(得分:0)
请在您的存在代码中进行以下更改
也保持idSeed的价值。
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...