处理iBatis NestedSQLException [英] Handling iBatis NestedSQLException
本文介绍了处理iBatis NestedSQLException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Java应用程序,尝试在表中插入一行,并且将com.ibatis.common.jdbc.exception.NestedSQLException
引发原因com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException
当我尝试为唯一键约束插入重复数据时.
I have a java app that try to insert a row into the table and com.ibatis.common.jdbc.exception.NestedSQLException
is thrown with the Cause com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException
When I try to insert dublicate data for a unique-key constraint.
如何捕获该异常?
推荐答案
要找到根本原因,您可以执行以下操作:
To get to the root cause you can do something like this:
try {
//insert
} catch (NestedSQLException e) {
Throwable t = e;
while(t.getCause() != null) {
t = t.getCause();
}
//in your situation, now t should be MySQLIntegrityConstraintViolationException
if (t instanceOf MySQLIntegrityConstraintViolationException) {
//do something
}
}
这篇关于处理iBatis NestedSQLException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文