Java Reference
In-Depth Information
When you insert the duplicate vehicle again, notice that Apache Derby returns the following error
code and SQL state:
Error code : -1
SQL state : 23505
If you refer to the Apache Derby reference manual, you will find the error code description shown in
Table 3-2.
Table 3-2. Apache Derby's Error Code Description
SQL State
Message Text
23505
The statement was aborted because it would have caused a duplicate key value in a
unique or primary key constraint or unique index identified by '< value >' defined
on '< value >'.
How does the Spring JDBC framework know that state 23505 should be mapped to
DuplicateKeyException ? The error code and SQL state are database specific, which means different
database products may return different codes for the same kind of error. Moreover, some database
products will specify the error in the errorCode property, while others (like Derby) will do so in the
SQLState property.
As an open Java application framework, Spring understands the error codes of most popular
database products. Because of the large number of error codes, however, it can only maintain mappings
for the most frequently encountered errors. The mapping is defined in the sql-error-codes.xml file,
located in the org.springframework.jdbc.support package. The following snippet for Apache Derby is
taken from this file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 3.0//EN"
" http://www.springframework.org/dtd/spring-beans-3.0.dtd ">
<beans>
...
<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>
 
Search WWH ::




Custom Search