Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-12-2008, 04:24 PM
Member
 
Join Date: Feb 2008
Posts: 7
kasipandian is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-22-2008, 04:24 AM
Member
 
Join Date: Apr 2007
Location: USA
Posts: 50
derrickD is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-22-2008, 04:46 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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)
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-22-2008, 07:13 AM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 183
danielstoner is on a distinguished road
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:
Code:
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
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-22-2008, 07:20 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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)
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-22-2008, 08:39 AM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 183
danielstoner is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-22-2008, 08:42 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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)
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-23-2008, 07:54 PM
Member
 
Join Date: Feb 2008
Posts: 7
kasipandian is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-23-2008, 09:39 PM
Member
 
Join Date: Apr 2007
Location: USA
Posts: 50
derrickD is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-24-2008, 05:23 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,403
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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)
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-25-2008, 06:00 PM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
rjuyal is on a distinguished road
Quote:
'm using Spring DAO
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
Code:
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CRC check program 1 error javakid9000 New To Java 1 03-19-2008 06:04 AM
Posting codes and help Java_Man New To Java 2 02-16-2008 04:15 AM
Getting ASCII codes of character gapper New To Java 1 02-02-2008 10:42 AM
Error: Cannot delete a.txt:It is being used by another person or program trill Advanced Java 1 08-07-2007 08:34 AM
Error :Invalid path, C:\Program Files\Java\j2re1.4.2_06\bin\javac.exe silvia New To Java 2 07-30-2007 09:55 AM


All times are GMT +3. The time now is 11:53 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org