Just prepare your Statement
as follows
PreparedStatement ps = connection.prepareStatement(
INSERT_TRAN_SQL, Statement.RETURN_GENERATED_KEYS);
The underlying JDBC driver (used indirectly through the Spring's JdbcTemplate
here) requires a hint that you would like to retrieve the generated keys. This can be done either while preparing a PreparedStatement
as
connection.prepareStatement(strSQL, Statement.RETURN_GENERATED_KEYS);
or, at the time of executing a Statement
as
statement.executeUpdate(strSQL, Statement.RETURN_GENERATED_KEYS);
This is what your java.sql.SQLException
is pointing at as well.