捕获重复条目异常
问题描述:
我如何捕获此异常:
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");
}