日期:2014-05-16 浏览次数:20510 次
spring在org.springframework.jdbc.support这个包的sql-error-codes.xml里面定义了常用数据库的错误代码,我们可以根据这些错误代码定位sql的基本问题。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> <!-- - Default SQL error codes for well-known databases. - Can be overridden by definitions in a "sql-error-codes.xml" file - in the root of the class path. - - If the Database Product Name contains characters that are invalid - to use in the id attribute (like a space) then we need to add a property - named "databaseProductName"/"databaseProductNames" that holds this value. - If this property is present, then it will be used instead of the id for - looking up the error codes based on the current database. --> <beans> <bean id="DB2" class="org.springframework.jdbc.support.SQLErrorCodes"> <property name="databaseProductName"> <value>DB2*</value> </property> <property name="badSqlGrammarCodes"> <value>-007,-029,-097,-104,-109,-115,-128,-199,-204,-206,-301,-408,-441,-491</value> </property> <property name="dataIntegrityViolationCodes"> <value>-407,-530,-531,-532,-543,-544,-545,-603,-667,-803</value> </property> <property name="dataAccessResourceFailureCodes"> <value>-904,-971</value> </property> <property name="transientDataAccessResourceCodes"> <value>-1035,-30080,-30081</value> </property> <property name="deadlockLoserCodes"> <value>-911,-913</value> </property> </bean> <bean id="Derby" class="org.springframework.jdbc.support.SQLErrorCodes"> <property name="databaseProductName"> <value>Apache Derby</value> </property> <property name="useSqlStateForTranslation"> <value>true</value> </property> <property name="badSqlGrammarCodes"> <value>42802,42821,42X01,42X02,42X03,42X04,42X05,42X06,42X07,42X08</value> </property> <property name="dataIntegrityViolationCodes"> <value>22001,22005,23502,23503,23505,23513,X0Y32</value> </property> <property name="dataAccessResourceFailureCodes"> <value>04501,08004,42Y07</value> </property> <property name="cannotAcquireLockCodes"> <value>40XL1</value> </property> <property name="deadlockLoserCodes"> <value>40001</value> </property> </bean> <bean id="H2" class="org.springframework.jdbc.support.SQLErrorCodes"> <property name="badSqlGrammarCodes"> <value>42000,42001,42101,42102,42111,42112,42121,42122,42132</value> </property> <property name="dataIntegrityViolationCodes"> <value>22003,22012,22025,23000,23001</value> </property> <property name="dataAccessResourceFailureCodes"> <value>90046,90100,90117,90121,90126</value> </property> </bean> <bean id="HSQL" class="org.springframework.jdbc.support.SQLErrorCodes"> <property name="databaseProductName"> <value>HSQL Database Engine</value> </property> <property name="badSqlGrammarCodes"> <value>-22,-28</value> </property> <property name="dataIntegrityViolationCodes"> <value>-9</value> </property> <property name="dataAccessResourceFailureCodes"> <value>-80</value> </property> </bean> <bean id="Informix" class="org.springframework.jdbc.support.SQLErrorCodes"> <property name="databaseProductName"> <value>Informix Dynamic Server</value> </property> <property name="badSqlGrammarCodes"> <value>-201,-2