sql - Manage Exceptions in Java -
i'm doing small database program.
connection connection = drivermanager.getconnection(..., ..., ...); string createtable= "create table employee ..."; try { statement stmt = connection.createstatement (); stmt.executeupdate(createtable); stmt.close(); connection.close (); } catch(exception ex) { system.out.println("erreur : " + ex.tostring()); }
when run program going fine, second time exception :
duplicate table name : employee
ok fine know how manage exceptions, how managing every possible exception. :
if
exception duplicattion error then
display custom duplicate message.
if
it's duplicate primary key then
display error message , on.
thanks.
you'll have parse exceptions method string "subtype" of actual sql exception:
try { // ... } catch (sqlexception e) { if (e.getmessage().tolowerstring().contains("duplicate table name")) { // handle duplicate table name problem } else if ( /* ... */ ) { // ... } }
Comments
Post a Comment