File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Handling SQLException 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 SQLException" Watch "Handling SQLException" New topic

Handling SQLException

arfeen khan

Joined: May 13, 2011
Posts: 25
Is there any way to fetch the column name name for which SQL exception occurred?

For example a table MyTable is defined as --

Now if issue following insert it will raise ORA-01722-
INSERT INTO testchild VALUES(5, 'tes')
as AGE column expects a number, but we are providing a string.
So i want in my JDBC program to get for which column (here age) this error occurred.

Please help on this.
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 149
Hi Afreen,

could you please post the code that you have tried so far?

Martin Vajsar

Joined: Aug 22, 2010
Posts: 3733

Unfortunately, Oracle doesn't report name of the column that "caused" the exception, most probably because this exception could generally occur in any expression, even in expressions that relate either to none, or several columns at once. I don't know of any way to overcome this.

Edit: you should carefully avoid implicit conversions in your code; if you do, you won't encounter this exception. When searching for a bug lurking in the code, you could employ either extensive logging or debugging to nab (and crush! ) the bug.
arfeen khan

Joined: May 13, 2011
Posts: 25
Thank you all for posting the reply.
Though there was not a exact answer, but some how satisfying response.
I agree. Here's the link:
subject: Handling SQLException
jQuery in Action, 3rd edition