Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling JDBC Errors in Exceptions

 
Nick Delauney
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic