捕获重复条目异常 [英] Catch duplicate entry Exception
本文介绍了捕获重复条目异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何捕获此异常:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
Duplicate entry '22-85' for key 'ID_CONTACT'
推荐答案
我使用spring,因此我们可以通过org.springframework.dao.DataIntegrityViolationException
I use spring so we resolve it by org.springframework.dao.DataIntegrityViolationException
try {
ao_history_repository.save(new AoHistory(..));
}
catch (DataIntegrityViolationException e) {
System.out.println("history already exist");
}
这篇关于捕获重复条目异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文