This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Oracle/OAS and the fly likes Parse Oracle error code and message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Parse Oracle error code and message" Watch "Parse Oracle error code and message" New topic
Author

Parse Oracle error code and message

Rithanya Laxmi
Ranch Hand

Joined: Jan 24, 2011
Posts: 135
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

Joined: Jul 20, 2009
Posts: 188
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

Joined: Jan 24, 2011
Posts: 135
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

Joined: Oct 13, 2005
Posts: 37940
    
  22
Question too difficult for “beginning”. Moving to the Oracle forum.
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 188
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

Joined: Jul 20, 2009
Posts: 188
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

Joined: Aug 22, 2010
Posts: 3606
    
  60

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Parse Oracle error code and message
 
Similar Threads
Cannot insert record into Database!
getNextException SQLGrammarException
Perf Tests failing badly on mysql
Error at session.flush()
MySQL, Hibernate, and allowNanAndInf Flag