JDBC异常抽象
Spring会将数据操作的异常转换为DataAccessException
解析错误码
- SQLErrorCodeSQLExceptionTranslator
- ErrorCode定义
- org/springframework/jdbc/support/sql-error-codes.xml
- classpath下的sql-error-codes.xml(定制)
org/springframework/jdbc/support/sql-error-codes.xml
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.
<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="duplicateKeyCodes"> <value>23001,23505</value> </property> <property name="dataIntegrityViolationCodes"> <value>22001,22003,22012,22018,22025,23000,23002,23003,23502,23503,23506,23507,23513</value> </property> <property name="dataAccessResourceFailureCodes">