I want to insert a row into a table using PreparedStatement. The table got 3 columns(int, String, String). The thing is that the int column is AUTO_INCREMENT, so I want to l
If the field is already autoincrement, it is enough to populate just the other two fields. Here an example
String sql = "INSERT INTO mytableName("
+ "fistStringColumnName,"
+ "secondStringColumnName) "
+ "VALUES(?,?)";
try (PreparedStatement pstmt = connection.prepareStatement(sql)) {
// Set the values
pstmt.setString(1, "firstString");
pstmt.setString(2, "secondString");
// Insert
pstmt.executeUpdate();
} catch (SQLException e) {
} catch (FileNotFoundException e) {
}