File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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
Bookmark "Handling SQLException" Watch "Handling SQLException" New topic
Author

Handling SQLException

arfeen khan
Greenhorn

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 --
UID NOT NULL NUMBER
AGE NUMBER

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: 136
Hi Afreen,

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

Thanks
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

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
Greenhorn

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Handling SQLException