Results 1 to 11 of 11
- 05-12-2008, 03:24 PM #1
Member
- Join Date
- Feb 2008
- Posts
- 7
- Rep Power
- 0
How to get error codes using java program
Dear Friends,
My requirement is to get the SQL error code through my program whenever the exception thrown. I've to show this error code in JSP. Now I'm getting a error codes with messages. I'm using spring frame work. So If there any database related exceptions I'm getting DataAccessException . I don't know how to get the error code from DataAccessException to . In SQLException we have a method getErrorCode(). However I'm not getting any SQLException, So I cannot use this. So please help me to get the error code from DataAccessException . Any help would be appreciated.
Thanks
Kasi.Last edited by kasipandian; 05-12-2008 at 03:27 PM.
- 05-22-2008, 03:24 AM #2
Member
- Join Date
- Apr 2007
- Location
- USA
- Posts
- 50
- Rep Power
- 0
Doesn't DataAccessException have a getMessage() method??
I use that one and I am pretty sure I have seen the ORA errors on my screen when they occur.
- 05-22-2008, 03:46 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Can you tel me how did you communicating with your database?
- 05-22-2008, 06:13 AM #4
Try DataAccessException.getCause(). It should return a cause exception. You can walk the cause chain and maybe you can find the SQLException somewhere in there. The signature is:
You can check the type of exception with instanceof.Java Code:public Throwable getCause()
Daniel @ [www.littletutorials.com]
Language is froth on the surface of thought
- 05-22-2008, 06:20 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yep, but daniel I think it is possible only with JDBC. With Hibernate we can't do it. Correct me if I'm wrong.
- 05-22-2008, 07:39 AM #6
Honestly I didn't use Hibernate for a while now so I don't remember this detail.
Daniel @ [www.littletutorials.com]
Language is froth on the surface of thought
- 05-22-2008, 07:42 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
As far as I remember it's true. I'll check it and let you know. Not now ;)
- 05-23-2008, 06:54 PM #8
Member
- Join Date
- Feb 2008
- Posts
- 7
- Rep Power
- 0
Hi friends
I'm using Spring DAO and getting connection from the server using JNDI look up. I can able to get the error message. However I want to display the error code in the JSP. Is there any way to do it?
Thanks
Kasi.
- 05-23-2008, 08:39 PM #9
Member
- Join Date
- Apr 2007
- Location
- USA
- Posts
- 50
- Rep Power
- 0
I am using struts2 and just catch the error in my action and then display it with an actionError("Error "+e.getMessage());
It is displayed in the jsp then.
- 05-24-2008, 04:23 AM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Well explained error message is mush better. Why you guys worried about error codes. ;) There are much better ways to handle exceptions in Java.
- 05-25-2008, 05:00 PM #11
If you mean Spring Framework, then'm using Spring DAO
In your DaoImpl, throw the SQLException, pass it to controller via Model ( i guess you have done this already ). In controller catch the SQLexception. useyou can set this in your messages.properties also.Java Code:errors.reject ( "DB Error", new Object[] { new Integer ( sqlException.getErrorCode() ) , sqlException.getCause().getMessage()}, "DB Error: {0} : {1}" );i am the future
Similar Threads
-
CRC check program 1 error
By javakid9000 in forum New To JavaReplies: 1Last Post: 03-19-2008, 05:04 AM -
Posting codes and help
By Java_Man in forum New To JavaReplies: 2Last Post: 02-16-2008, 03:15 AM -
Getting ASCII codes of character
By gapper in forum New To JavaReplies: 1Last Post: 02-02-2008, 09:42 AM -
Error: Cannot delete a.txt:It is being used by another person or program
By trill in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 07:34 AM -
Error :Invalid path, C:\Program Files\Java\j2re1.4.2_06\bin\javac.exe
By silvia in forum New To JavaReplies: 2Last Post: 07-30-2007, 08:55 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks