Because I had this problem and I could not find a list of MySQL error codes on the Internet, I’ve decided to implement my own MySQL error codes enum. It is based on MySQL 5.1.35 sources, include/mysqld_ername.h file.
Now I can do something like this:

[java]
catch (SQLException e) {
if(e.getErrorCode() == MySQLExceptionCode.ER_DUP_ENTRY.getErrorCode()){
r = Result.DUPLICATE_ACCOUNT_NO;
} else
r = Result.DATABASE_ERROR;
}
[/java]

You can find the java file here.