Reputation: 23
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
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