This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Getting MEAN with Mongo, Express, Angular, and Node and have Simon Holmes on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Handling JDBC Errors in Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Handling JDBC Errors in Exceptions" Watch "Handling JDBC Errors in Exceptions" New topic
Author

Handling JDBC Errors in Exceptions

Nick Delauney
Ranch Hand

Joined: Sep 28, 2002
Posts: 43
Is there a generic way to get the details of an error so that handiling exceptions with custom messages for the user can work across databases?

I have SQL code that could generate a insertion of duplicate primary key SQLException and could generate a duplicate unique id SQLException. I am working with SQL Server, but we will be migrating to DB2 soon.

My thoughts were with getting the SQLException error code, but I think thats particular to databases?


N.D:"Anything worth having, takes time to get"
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31890
    
197

Nick,
Unfortunately you are correct that the code is database specific. Java 5 or 6 (I forget which, but I think it is 6) is supposed to solve this problem by providing more specific SQLException subclasse.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Handling JDBC Errors in Exceptions