SQL exception

hi,

when doing a DB operation, the database might throw an exception. like if we try to insert another record with an already existing primary key. is it possible to get this error message and pass it on to the java program ?

for example,

insertRow( ) throws an SQL exception if a database access error occurs, if this method is called when the cursor is not on the insert row, or if not all of non-nullable columns

in the insert row have been given a value.

but the DataBase might throw an exception for various other reasons - like the one i mentioned. Is there a way to catch those exceptions ?

thanks in advance

regards

anagha.

[695 byte] By [anagha] at [2007-9-26 5:32:09]
# 1

Hi anagha,

Catch your exceptions then use the error code in a switch to give an appropriate message eg.

try{

....

}

catch(SQLException sqle) {

int errorcode = sqle.getErrorCode();

Switch(errorcode) {

case 1: System.out.println("Primary key violation"); break;

case 2291: System.out.println("Integrity constraint violation"); break;

default: System.out.println("Other violation " + sqle.getMessage());

}

}

Richard

Rijaos at 2007-6-29 19:42:49 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...