• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to find which column had large value through Exception Handling

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depends on the database as to what you get back from the db call.
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic