Use Statement#getGeneratedKeys() and Statement#executeUpdate(String, int) (this is a JDBC 3.0 function, your database must support JDBC 3.0).
Here is an example that returns a ResultSet with values ββfor automatically generated columns in table 1:
Statement stmt = conn.createStatement(); int rows = stmt.executeUpdate("INSERT INTO TABLE1 (C11, C12) VALUES (1,1)", Statement.RETURN_GENERATED_KEYS); ResultSet rs = stmt.getGeneratedKeys();
source share