-3

im currently getting this error when i run my programs query,

java.sql.SQLException: Column count doesn't match value count at row 1

but i dont know why , all my values are there and match up. this is the code were i do my sql statement.

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();
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user3225981
  • 107
  • 7

2 Answers2

3

Your SQL syntax is incorrect. It must be

INSERT INTO entry ( id, name, title, note) VALUES (?,?,?,?)
ThomasThiebaud
  • 11,331
  • 6
  • 54
  • 77
0

please do the following changes in your existence code,

maintain idSeed's value too.

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...
Shivam
  • 649
  • 2
  • 8
  • 20
Vishal Gajera
  • 4,137
  • 5
  • 28
  • 55