user985133
user985133

Reputation: 23

PreparedStatement No Value Specified for Parameter One

Having issues with this the one that needs to be set is a auto increment integer so how would I Specify that

PreparedStatement stmt = conn.prepareStatement("INSERT INTO `"+OnlineUsers.table2+"` VALUES (?,?,?)");

//What I do here
stmt.setInt(2, currentonline);
stmt.setDate(3, new java.sql.Date(b.getTime()));
stmt.execute();

Upvotes: 2

Views: 1809

Answers (1)

Mark Byers
Mark Byers

Reputation: 838196

It's best to specify the column names explicitly:

"INSERT INTO `" + OnlineUsers.table2 + "` (col2, col3) VALUES (?,?)"

Then:

stmt.setInt(1, currentonline);
stmt.setDate(2, new java.sql.Date(b.getTime()));

This will make your code robust to the order of the columns changing in the database.

Note: If OnlineUsers.table2 comes from an untrusted source you should validate this string, otherwise you could be at risk of an SQL injection attack.

Upvotes: 2

Related Questions