• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection validity check

 
Prashant Neginahal
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

How to know that whether a not-null connection is a valid connection?
Valid i mean, it should execute statements. I dont want to execute any statments and then get exception and then come to know that connection is NOT valid.

if(conn != null){
// Is there any check to know that this connection is valid.
}

Thanks,
Prashant
 
craig a chapman
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be handling all exceptions when executing connection methods as a matter of course. Whether that is to log the exception message to a file or display a message to the user or both is your choice.

If you have the correct driver, specified the correct url and the database is running, the connection should be fine but you need to handle scenarios such as database server not running etc.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic