I am trying to insert the data in the Oracle Database table by using the java.sql.PreparedStatement. I am, however, not able to get the autogenerated keys. The issue here is after running the
statement.executeUpdate();
I am getting the exception saying the col1 cannot be null. Isn't it supposed to generate the col1 value and upload it in the database? Not sure what I am missing here.
I am new to the JDBC implementation so seeking help. Thank you.
col1: column to store auto-generated ID. col2 and col3 to store other data.
DAO:
PreparedStatement statement;
String query ="INSERT INTO table("col2", "col3") VALUES(?,?)";
statement = getConnection().prepareStatement(query, new String[]{ "col1" });
//add values to the statement for these two columns(col2 and col3) for this row in this step
statement.executeUpdate();
The database column to store the ID is non-nullable and is not set to autoincrement.