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
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 package. The following snippet for Apache Derby is
taken from this file:
<?xml version="1.0" encoding="UTF-8"?>
" ">
<bean id="Derby" class="">
<property name="databaseProductName">
<value>Apache Derby</value>
<property name="useSqlStateForTranslation">
<property name="badSqlGrammarCodes">
Search WWH ::

Custom Search