• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get the first occurance of ":" in a string  RSS feed

 
Rithanya Laxmi
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an error message string like below :-


java.sql.BatchUpdateException: ORA-12899: value too large for column "TDDS"."CUSTOMER"."ORDERNAME" (actual: 302, maximum: 255)

I am parsing the string using the ":" so that i will get the oracle error code and message like:-

OracleErrCode :ORA-12899
OracleErrMsg :value too large for column "TDDS"."CUSTOMER"."ORDERNAME" (actual: 302, maximum: 255)

But how i can get the first occurance of ":" so that i can get the above because there are few more
":" available for (actual: 302, maximum: 255)?

Hence please clarify how to get the first occurance of ":"?


Thanks.





 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your problem may be in using the nextElement method, rather than nextToken.

However, I don't think you are approaching this problem correctly. You simply want to:
1) Identify the position of the oracle error code
2) Extract the code
3) Extract the text after the code as the error message.

Hence, I don't think you need to split the entire exception message up. you should be able to complete step 1 easily (using the indexOf method). How about attempting all the steps again and showing us the code you come up with.

 
Rithanya Laxmi
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Using nextToken() also didnt yield me correct result. How to get the error message after error code without parsing it with a delimeter? Any code or help is highly appreeciated.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, you have the error code extracted? If so, how did you do it?
 
Rithanya Laxmi
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No James, I have not extracted the errorcode, I thougt of using ":" as a delimeter to extract the error code & message. But since the error message contains few more ":" (actual: 302, maximum: 255) . I have a problem extracting the error code as it will extract the data as below:-

errorCode : value too large for column "TDDS"."CUSTOMER"."ORDERNAME" (actual
errorMessage : actual: 302, maximum: 255)

which is wrong as it always parse the delimeter( which is the last one, hence how to parse the first occurance of ":" values ? Please clarify.

 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider using the techniques explained here:http://docs.oracle.com/javase/tutorial/jdbc/basics/sqlexception.html where you get the values from the SqlException e.g


 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rithanya Laxmi wrote:No James, I have not extracted the errorcode, I thougt of using ":" as a delimeter to extract the error code & message. But since the error message contains few more ":" (actual: 302, maximum: 255) .

I guess it depends on where these error messges are and why you're doing this.

If they're in a log file, then I suspect you may have all sorts of other messages that you don't want to parse. However, if you're doing this inside your program and ONLY on SQLException's, there'll be a lot less work.

Either way, I suspect you'll want to use something like String.startsWith() to make sure you're actually parsing the right kind of message.

Personally, if I was trying to do this, I'd probably do something like:because then I'd know that any array it returns whose length is 2 was an Oracle error message with a colon.

But it's only ONE way of doing it.

Winston
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was thinking along the lines of:
With both indexes identified, you should be able to extract the error code and the message (which is the remaining text after the colon which follows the error code).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!