Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

exception handling

 
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
 
Marshal
Posts: 69472
277
  • 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.
 
Ranch Hand
Posts: 2908
1
Spring Java 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.
 
What are your superhero powers? Go ahead and try them on this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic