I do some insert in a MySQL DB with a for cycle.
I have a problem with the auto-increment, 'cause after the first insert I obtain an com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException.
Here the code:
for (int i=0; i<numKeys; i++) {
try {
stm1 = this.db_connection.prepareStatement("INSERT INTO mytable (Cod, Prop, Field, Value) VALUES (?,?,?,?)");
stm1.setInt(1, Statement.RETURN_GENERATED_KEYS);
stm1.setInt(2, 0);
stm1.setString(3, aname);
stm1.setString(4, avalue);
stm1.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
Cod is an auto-increment-field.