I am trying to convert ibatis code to mybatis. my ibatis code is like
try {
sqlMap.insert("insertinfo", insertData);
}
catch (SQLException sqle) {
Logger.error("error occurred while inserting",sqle);
}
Now on mybatis,
try {
session.insert("insertinfo", insertData);
}
// what exception to catch ?? RuntimeSQLException or SqlSessionException
catch ( ?? sqle) {
Logger.error("error occurred while inserting",sqle);
}
I tried to use both RuntimeSQLException
and SqlSessionException
and both are working fine. But I don't know which one to use.
I found this post while I was searching similar issue with mybatis. This is the original question I had. Based on comments and my own research I am trying to give answer.
SQLException
is checked exception and Mybatis only support RuntimeException
so you cannot use SQLException
with mybatis.
SqlSessionException
is RuntimeException used by Mybatis. refer this
RunTimeSQLException
is basically a wrapper over the SQLException to facilitate passing of actual SQLException i.e the one thrown by the JDBC driver unlike others which are exceptions related to Mybatis operations source