• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parse Oracle error code and message

 
Rithanya Laxmi
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • 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.
 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • 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: 185
  • Mark post as helpful
  • send pies
  • 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.

 
Campbell Ritchie
Sheriff
Pie
Posts: 49364
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question too difficult for “beginning”. Moving to the Oracle forum.
 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • 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: 197
  • Mark post as helpful
  • send pies
  • 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...
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic