SQLException.getSQLState的所有可能值是什么? [英] What are all the possible values for SQLException.getSQLState?

查看:1367
本文介绍了SQLException.getSQLState的所有可能值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQLException.getSQLState 检索 SQLException SQLState >对象。这种方法可以返回的所有可能的值是什么?我可以使用该值来识别在数据库中发现的特定错误(即,该值是否告知我是PK违规还是唯一的约束,或列值大到等)?

SQLException.getSQLState retrieves the SQLState for the SQLException object. What are all the possible values that can be returned by this method? Can I use the value to identify specific errors that ocured in the database (i.e. can this value tell me if it was a PK violation, or a unique constraint, or column value to large etc)?

另外, DatabaseMetaData.getSQLStateType()方法应该指示是否返回的 SQLSTATE SQLException.getSQLState 是X / Open(现在称为Open Group)SQL CLI或SQL99。唯一可能的值应该是 DatabaseMetaData.sqlStateXOpen == 1 DatabaseMetaData.sqlStateSQL99 == 2 但我是获取值 0 。我是否缺少某些东西?

Also, the DatabaseMetaData.getSQLStateType() method is supposed to indicate whether the SQLSTATE returned by SQLException.getSQLState is X/Open (now known as Open Group) SQL CLI or SQL99. The only possible value for this should be DatabaseMetaData.sqlStateXOpen == 1 and DatabaseMetaData.sqlStateSQL99 == 2 but I am getting the value 0. Am I missing something?

有没有办法可以使用上述方法的组合确定DB中出现的特定错误类型?可以指望 SQLException.getSQLState 的值吗?这些值是否与DB提供程序到DB提供程序不同?

Is there a way that I can determine the specific type of error that occurred in the DB using combinations from the above mentioned methods? Can I count on the values of SQLException.getSQLState? Are these values different from DB provider to DB provider?

推荐答案

包含SQLStates的官方文档显然可以在相对较高的价格,从ANSI和XOpen。
但是,大多数数据库的文档都有SQLState列表。可能最完整(可访问)的在线列表在DB2手册中。检查 DB2通用消息手册,例如。 Oracle(需要TechNet密码)和Sybase等等也有在线列表。

Official documents that include SQLStates can obviously be purchased, at a relatively high price, from ANSI and XOpen. But, the documentation for most databases have lists of SQLStates. Probably the most complete ( and accessible ) online listings are in the DB2 manuals. Check the DB2 Universal Messages manual, for instance. Oracle ( TechNet password required ) and Sybase, among others, also have online listings.

关于第二个问题,这是SQLState的意图,然而,各种数据库具有不同程度的依从性。例如,一些将多个本机错误消息映射到同一个SQLState。对于通用使用,应该专注于主要代码(SQLState的前两个字符),然后确定在次要代码中是否有更多的具体信息(超出000.)。

As to the second question, this is the intent of SQLState, however, the various databases have varying degrees of compliance. For example, some map multiple native error messages to the same SQLState. For generic use, one should probably concentrate on the major code ( the first two characters of SQLState, ) then determine if more specific info is available in the minor code ( beyond 000. )

http://www.jguru.com/faq/view.jsp ?EID = 46397

这篇关于SQLException.getSQLState的所有可能值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆