|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

05-12-2008, 04:24 PM
|
|
Member
|
|
Join Date: Feb 2008
Posts: 7
|
|
|
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 04:27 PM.
|
|

05-22-2008, 04:24 AM
|
|
Member
|
|
Join Date: Apr 2007
Location: USA
Posts: 50
|
|
|
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.
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-22-2008, 04:46 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
|
|
|
Can you tel me how did you communicating with your database?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 13, 2008)
|
|

05-22-2008, 07:13 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Canada
Posts: 183
|
|
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:
public Throwable getCause()
You can check the type of exception with instanceof.
__________________
Daniel @ [ To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. ]
Language is froth on the surface of thought
|
|

05-22-2008, 07:20 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
|
|
|
Yep, but daniel I think it is possible only with JDBC. With Hibernate we can't do it. Correct me if I'm wrong.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 13, 2008)
|
|

05-22-2008, 08:39 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Canada
Posts: 183
|
|
|
Honestly I didn't use Hibernate for a while now so I don't remember this detail.
__________________
Daniel @ [ To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. ]
Language is froth on the surface of thought
|
|

05-22-2008, 08:42 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
|
|
As far as I remember it's true. I'll check it and let you know. Not now 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 13, 2008)
|
|

05-23-2008, 07:54 PM
|
|
Member
|
|
Join Date: Feb 2008
Posts: 7
|
|
|
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, 09:39 PM
|
|
Member
|
|
Join Date: Apr 2007
Location: USA
Posts: 50
|
|
|
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.
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-24-2008, 05:23 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
|
|
Well explained error message is mush better. Why you guys worried about error codes. There are much better ways to handle exceptions in Java.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 13, 2008)
|
|

05-25-2008, 06:00 PM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
|
|
If you mean Spring Framework, then
In your DaoImpl, throw the SQLException, pass it to controller via Model ( i guess you have done this already ). In controller catch the SQLexception. use
errors.reject ( "DB Error", new Object[] { new Integer ( sqlException.getErrorCode() ) , sqlException.getCause().getMessage()}, "DB Error: {0} : {1}" );
you can set this in your messages.properties also.
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|