• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception handling

 
lokesh jain
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51456
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
lokesh jain
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I have done it putting an if condition inside exception block.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic