i get the following error when I execute the prepared statement. I use ms-access for my database
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 10.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3148)
.....
Here is my prepared statement
addUserSt = con.prepareStatement("insert into Accounts(Username, First_name, last_name, gender, birthday, email, civil_status, password, role, date_join) values(?,?,?,?,CDATE(?),?,?,?,?, sysdate)");
and here’s how i execute that prepared statement… the variables here are all strings
dc.addUserSt.setString(1, uname);
dc.addUserSt.setString(2, fname);
dc.addUserSt.setString(3, lname);
dc.addUserSt.setString(4, gender);
dc.addUserSt.setString(5, bday);
dc.addUserSt.setString(6, email);
dc.addUserSt.setString(7, civil);
dc.addUserSt.setString(8, pass);
dc.addUserSt.setString(9, role);
I can’t understand why I get that too few parameters error, i think that i setString well the prepared statement. when I remove the sysdate and remove also the date_join in the columns, the program runs perfectly. But i need to get the current date to store in the database.
Any help will be appreciated 🙂
sysdate is not valid function. Use Date() instead.
And don’t forget the parenthesis when using functions.