Take the 2-minute tour ×

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()));
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

It's best to specify the column names explicitly:

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


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.

share|improve this answer
Thanks worked You are awesome –  user985133 Oct 8 '11 at 7:51
add comment

Your Answer


