如何确定返回了哪个 SQLException/错误代码列表在哪里?
我正在使用 com.mysql.jdbc.Driver (如果它意味着什么)。 我希望能够捕获并正确处理从 MySQL 收到的异常。我想知道事务是否失败,是否已经存在带有我尝试插入的值的主键,以及所有其他错误。
我想做一些像
try
{
... // Code
}
catch(SQLException e)
{
switch(e.getErrorCode())
{
case...
case...
default...
}
}
我尝试过寻找的事情,但没有找到任何,只有一些谈论 C# / .net 的条目
我想要这样做的主要原因是看看我的其中一个事务是否因为隔离级别而回滚我说,在这种情况下,我必须重试。当然,还有其他一些问题。
非常感谢您的帮助!
I'm using com.mysql.jdbc.Driver (If it means anything).
I want to be able to catch and properly process the exceptions I receive from MySQL. I want to know if the transaction failed, if there's already a primary key with the value I'm trying to insert, and all the other errors.
I want to do something like
try
{
... // Code
}
catch(SQLException e)
{
switch(e.getErrorCode())
{
case...
case...
default...
}
}
I've tried looking, but haven't found any, only some entries which talk about C# / .net
The main reason I want this is to see if one of my transactions rolled back because of the Isolation level I put, in that case, I'll have to retry it. And of course, some other issues.
Your help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
需要驱动程序信息,因为返回的错误代码是供应商特定的。请查看以下 mysql 错误代码,可能会有所帮助 http://www .briandunning.com/error-codes/?source=MySQL
drivers information is required, as the error codes returned are vendor specific. Please have a look at the following error codes for mysql, might be helpful http://www.briandunning.com/error-codes/?source=MySQL
MySQL错误代码都记录在手册中(令人惊讶!)
http ://dev.mysql.com/doc/refman/5.1/en/error-handling.html
The MySQL error codes are all documented in the manual (surprise!)
http://dev.mysql.com/doc/refman/5.1/en/error-handling.html