-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();
2
  • 2
    Values tag should be like VALUES (?,?,?,?); Commented Dec 3, 2015 at 7:41
  • are you getting correct output ? i have doubt in it. i mean other changes need rather than insert query. Commented Dec 3, 2015 at 8:09

2 Answers 2

3

Your SQL syntax is incorrect. It must be

INSERT INTO entry ( id, name, title, note) VALUES (?,?,?,?)
Sign up to request clarification or add additional context in comments.

Comments

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...

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.