我试图将我的数据库和web应用程序从PostgreSQL转移到MySQL,应用程序使用的是play 2.3.0。
我让这个应用程序与MySQL一起工作,但我还没有进行错误管理,我需要您的帮助:
原始代码使用PSQLException,如下所示:
import org.postgresql.util.PSQLException
try {
SQL("DELETE FROM Lab WHERE id = {id}")
.on("id" -> lab.id)
.executeUpdate()
true
} catch {
case e: PSQLException
if e.getMessage.contains("update or delete on table \"lab\" violates foreign key constraint \"conference_organizedby_fkey\" on table \"conference\"") |
e.getMessage.contains("update or delete on table \"lab\" violates foreign key constraint \"appuser_lab_fkey\" on table \"appuser\"")
=> Logger.warn(e.getServerErrorMessage.getMessage); false
}对于这类错误,我找不到最好的MySQL错误处理程序。
你觉得我该用什么?
发布于 2015-05-12 08:05:46
只需捕获SQLException ( PSQLException是其中的一个实现),并坚持它的方法-即getMessage()
除非您确实需要PSQLException提供的额外信息,否则最好不要知道异常的实际类,因为这样就无法将处理程序绑定到JDBC连接路径。
https://stackoverflow.com/questions/30183940
复制相似问题