This discussion is archived
1 Reply Latest reply: Jan 17, 2007 2:47 PM by 807607 RSS

Datasource question

807607 Newbie
Currently Being Moderated
Hello. I am having some trouble with telling whether a datasource object is connected to the data source. I have a datasource class and connection specified properly with the correct driver, url, and connection.

Anways I also have a test program that will do a number of things assuming the data source is connected. I am assuming I havn't done it properly since the test program does nothing but build.

Heres part of my datasource class
static boolean isConnected(){
  try{
         

          if (con.isClosed()){
              return false;
          }
          else{
              return true;
          }

       }
     catch (Exception e){
     System.out.println("Error: " + e.toString());
          
     }
          return true;
     } 
Here is the snippit of what the test program needs
 if (dbs.isConnected()){ // then blah blah blah blah not important right now
Any help is appreciated as always.
  • 1. Re: Datasource question
    807607 Newbie
    Currently Being Moderated
    Not sure what you're looking to do, but, one possible problem is, you are returning true if there's an excpetion, which is not the best approach. It would probably be easier if you just put that code into what ever method executes the sql command- check to see if the connection is non-null and available. If not, re-initialize it.