This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "exception handling" Watch "exception handling" New topic
Author

exception handling

lokesh jain
Ranch Hand

Joined: Feb 21, 2009
Posts: 58
Hi, I need some help regarding exception handling. I have built an application, in which i have thrown 3 exceptions and catching them all as well.
1) Exception for string out of bound ....working fine
2) Exception for invalid username and password (SQL Exception)--working fine
3) Exception when we try to connect to oracle database then i have thrown SQLTransientException....which is not working and does not give the message provided by me.It gives the message about invalid username and password which is thrown and catched through SQL Exception.

I need a particular exception which can handle jdbc connectivity exception.

Thanks in advance
Lokesh
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38436
    
  23
How on earth do you get a StringOutOfBoundsException? If you get one, you have almost certainly got a mistake in your code somewhere.
Can't you use an SQLException for failure to connect?
lokesh jain
Ranch Hand

Joined: Feb 21, 2009
Posts: 58
hi campbell, I have told you about these exceptions which are specific to my application. StringoutOfBoundException is necessary for that and yes, I can catch connection Exception in SQLException but I am catching this exception and printing my own customized message : Invalid Username/Password. Now I need to do the same for oracle connection problem.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

lokesh jain wrote:
3) Exception when we try to connect to oracle database then i have thrown SQLTransientException....which is not working and does not give the message provided by me.It gives the message about invalid username and password which is thrown and catched through SQL Exception.

Look, SQLExcption is base class for all kind of sql exception and java.lang.SQLTransientExceptionis subclass, now when connection throws an exception then it goes into SQLExcption catch block, with a proper message about connection faliure. So in short there is no need to catch SQLTransientException
lokesh jain wrote:
I need a particular exception which can handle jdbc connectivity exception.

java.lang.SQLExcption


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
lokesh jain
Ranch Hand

Joined: Feb 21, 2009
Posts: 58
Thanks, I have done it putting an if condition inside exception block.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: exception handling