How to catch SQLException in mybatis

…衆ロ難τιáo~ 提交于 2019-12-11 07:30:03

问题


I am trying to catch SQLException on mybatis but it is not allowing me to use this.

try{
session.insert("insertMyData", insertData);
}
catch (SQLException sqle) {  // mybatis not supporting SQLException 
   //exception handling code 
}

so instead I try to use SqlSessionException

try{
session.insert("insertMyData", insertData);
}
catch (SqlSessionException sqle) {  // mybatis support this
  //exception handling code 
}

but the issue using this is is not all SQL exceptions are caught. if I try to insert duplicate data it is not catching SQLIntegrityConstraintViolationException

Is there a way to catch all SQL exception in mybatis.

来源:https://stackoverflow.com/questions/47166153/how-to-catch-sqlexception-in-mybatis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!