Name: bsT130419 Date: 09/28/2001
java version "1.2.2"
Solaris VM (build Solaris_JDK_1.2.2_09, native threads, sunwjit)
I think, JDBC standard should cover the SQL errors that are common to all
RDBMSs. These could include common sql errors like
1. Primary Key violation while insert
2. Cannot delete data because of foreign key constraint
3....
In the current setup, the only way to do this is to look at the SQL Code and
SQL State through SQLException object thrown by JDBC. These error codes are
vendor dependent. If I have any logic in my code, that accesses the SQL code or
state, it looses the database independence, which is the most important
advantage of using JDBC.
Wouldn't it be nice if we could write something like the code below, where
UniqueKeyViolationException is a new class in the JDBC, which extends
SQLException?
<code>
PreparedStatement pstmt = conn.prepareStatement("Insert into ...");
.
.
.
try {
pstmt.executeUpdate();
}
catch ( UniqueKeyViolationException uEx ){
// Unique key violation happened, do the required business logic
}
catch ( SQLException sEx ){
// Some unexpected error; process appropriately
}
</code>
(Review ID: 132814)
======================================================================
java version "1.2.2"
Solaris VM (build Solaris_JDK_1.2.2_09, native threads, sunwjit)
I think, JDBC standard should cover the SQL errors that are common to all
RDBMSs. These could include common sql errors like
1. Primary Key violation while insert
2. Cannot delete data because of foreign key constraint
3....
In the current setup, the only way to do this is to look at the SQL Code and
SQL State through SQLException object thrown by JDBC. These error codes are
vendor dependent. If I have any logic in my code, that accesses the SQL code or
state, it looses the database independence, which is the most important
advantage of using JDBC.
Wouldn't it be nice if we could write something like the code below, where
UniqueKeyViolationException is a new class in the JDBC, which extends
SQLException?
<code>
PreparedStatement pstmt = conn.prepareStatement("Insert into ...");
.
.
.
try {
pstmt.executeUpdate();
}
catch ( UniqueKeyViolationException uEx ){
// Unique key violation happened, do the required business logic
}
catch ( SQLException sEx ){
// Some unexpected error; process appropriately
}
</code>
(Review ID: 132814)
======================================================================