• 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

Parse Oracle error code and message

 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have the below stacktrace here I need to parse only the Oracle error code and message:-



Here I need to parse retrive only :-

OracleErrorCode : ORA-0001
OracleErrorMsg : unique constraint (RRTS.RRTS_CUST_ID_PK) violated

Please clarify how we can proceed with it.

Thanks.
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Search exception.getMessage() for "ORA-".
2a. If it's contained split at ":" and you're done.
2b. If getMessage() does not contain "ORA-" try exception.getCause() and start over at 1 if getCause() does not return null.

 
Rithanya Laxmi
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. The exception.getMessage() returns only "org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update" and not
ORA-00001. Similarly the exception.getCause() returns only "ConstraintViolationException". Hence how we can get the respective Oracle error code & message? Please clarify.

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question too difficult for “beginning”. Moving to the Oracle forum.
 
Christian Dillinger
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rithanya Laxmi wrote:Thanks. The exception.getMessage() returns only "org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update" and not
ORA-00001. Similarly the exception.getCause() returns only "ConstraintViolationException". Hence how we can get the respective Oracle error code & message? Please clarify.



That's right, getMessage() returns what you said. That message does not contain any "ORA-"-parts. So that's 2b from my post. Call getCause() which gives you another Throwable. This one is not null, so start over with No. 1 on THAT throwable - didn't mention this explicitly because it was quite clear to me.

If the stacktrace above is correct, this getMessage() should bring "java.sql.BatchUpdateException: ORA-00001: unique constraint (RRTS.RRTS_CUST_ID_PK) violated".
Do this as long as:
- getCause() does not return null
OR
- getMessage() contains what you're looking for
 
Christian Dillinger
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Question too difficult for “beginning”. Moving to the Oracle forum.



That's not an oracle question, it's a question on how to analyze a stacktrace...
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also be aware that the language of the error message can change, depending on the locale settings of the machine the driver runs on. However, the ORA-XXXX code should be there in the same format regardless of the language.

And if you call stored procedures in your code (and perhaps in other circumstances too) the SqlException could actually contain an Oracle stack trace. Typically the would be PLS-XXXX error messages, and I believe there could be zero, one or even more ORA-XXXX messages. Quite a mess I'd say.
 
I didn't say it. I'm just telling you what this tiny ad said.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic