• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to find which column had large value through Exception Handling

 
meruva surendra
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have one table in database. Its columns lengths were fixed in table. What i did is i given values lengths are more than database columns lengths. So i want to know which column had the too large value using exception handling. Can anyone have idea on this. My java class is like this.

Advance Thanks

 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at DatabaseMeta#getColumns

Another approach (non java) is to query the database information_schema (MySQL and SQL Server) directly.
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on the database as to what you get back from the db call.
 
Tapas Chand
Ranch Hand
Posts: 583
8
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave is right. Different databases throw different error message.
Oracle clearly mentions the column name, column defined length and length of data trying to insert.
I cannot remember other databases' error messages.
What database you are using?
 
meruva surendra
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the Prompt Reply. I am using ORACLE Database. I am getting error like this

ORA-01438: value larger than specified precision allowed for this column ; nested exception is java.sql.BatchUpdateException:

so I want to tell the specific column has the larger value.
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ORA-01438 is for numeric values. 12899 would be what you'd see for a VARCHAR2 column.
I don't see any numeric values in your sample code above.
Are you sure it's not the contact number causing the issue?

Also, it depends on what version of Oracle you are using as to whether it gives you the column name in the error message. Looking at the message you posted it looks like you are on an earlier version.
I think they changed the message in 11?
 
Tapas Chand
Ranch Hand
Posts: 583
8
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes, my bad.
Oracle has different error messages for character and numeric types.
If OP will post the table description, things will be clear.
 
meruva surendra
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its sample code. But In my real project they are number of number values set to prepared statement. Whatever it may be whether varchar or numeric , just i wanna show the column name in the exception handling. Can we handle this???
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of Oracle are you on?

If it's a version before they changed the error text, then you might need to do something along the lines of what K. Tsang mentions, and check column info against the data to find the mismatch.

To be honest, you should be validating the data before it even gets here, though I realise mismatches can be introduced between the validation info and the actual database...then again, integration tests should pick those up.
 
meruva surendra
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for prompt replies. But my question is simple. see for example i have column mobile_number with length 10 in database table. now i am inserting lakshs of records. some records have 11 digits. So when inserting it show length exceeded error. so i wanna show like "Mobile number exceeded with this 234567890345 value" in exception handling. Just for example i took mobile_number, there may be number of columns.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic