This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv 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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Handling JDBC Errors in Exceptions" Watch "Handling JDBC Errors in Exceptions" New topic

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

Joined: May 26, 2003
Posts: 32819

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]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Handling JDBC Errors in Exceptions
It's not a secret anymore!