I am currently using MyBATIS in my project.
I sometimes need to run an INSERT query but ignore if the row I'm trying to insert is already present on DB, but instead handle other SQL errors.
How can I find that the SQLException is related to primary key violation?
Something like
try {
sqlMap.insert(query, params);
} catch (DuplicateKeyException ex) {
//Do nothing, it's OK for mew
} catch (SQLException ex) {
throw ex;
}
I suppose that specific exception doesn't really exist...
SQL isn't my strong point, but you could look into the Error Code and SQL State codes contained within the SQLException that would be thrown. Those may offer more insight into why the query failed.