Insert records using code in a table, where one of the fields is autoincremented (id). How I can find out what is the value of autoincremented field (id) on record that I just inserted?
PreparedStatement ps = null;
Connection con = null;
ResultSet rs = null;
int rows = 0;
try {
String SQL_DRV = "org.hsqldb.jdbcDriver";
String SQL_URL = "jdbc:hsqldb:hsql://localhost/localDB";
Class.forName(SQL_DRV);
con = DriverManager.getConnection(SQL_URL, "sa", "");
ps = con.prepareStatement(
"insert into infousuarios (nombre, apellidos, email) " +
"values (?, ?, ?)");
ps.setString(1, name);
ps.setString(2, surnames);
ps.setString(3, login+"@micorreo.com");
rows = ps.executeUpdate();
// How I can know the value of autoincrement field (id) of the record just enter??