I'm doing a Java application in conjunction with a MySQL database and would like to know what would be the best command to return an auto increment ID of the database shortly after the registry was entered.
My application will work with multiple concurrent accesses to the database, and would like a non-return type error to return a wrong ID that was entered by another user.
I'm using JDBC
and I retrieve the connection this way:
private static final String URL = "jdbc:mysql://localhost/exemplows";
private static final String USER = "XXXXXXXX";
private static final String SENHA = "XXXXXXX";
public static Connection obtemConexao() throws SQLException {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block e.printStackTrace();
}
return DriverManager.getConnection(URL, USER, SENHA);
}