vijay <[EMAIL PROTECTED]> writes:

> Hi,
>
> Please advice what's wrong in the following  Servlet. Iam not getting a
> value for Connection 'con':
>
>    public Connection handle()
>    {
>      Connection conn=null;
>      try {
>        Class.forName("oracle.jdbc.driver.OracleDriver");
>        conn = DriverManager.getConnection ("jdbc:oracle:oci8:@" ....
>      }catch(Exception e){}
>      return conn;
>    }

Your code is badly written, you should really check it more before you
send it to this list asking somone else to fix your problem.

Problems with the above method are:

1. you don't handle the exception 'e'
2. you don't throw an exception from the method on error
3. you return null when you don't want to

Try re-writing the method like this:


   public Connection handle()
     throws IllegalStateException
   {
     Connection conn=null;
     try {
       Class.forName("oracle.jdbc.driver.OracleDriver");
       conn = DriverManager.getConnection ("jdbc:oracle:oci8:@" ....
       return conn;
     }
     catch(Exception e)
     {
        // This line might give you a clue as to what is going wrong
        e.printSTackTrace();

        // This line allows the error to be signalled back to your app
        throw new IllegalStateException ("couldn't establish connection");
     }
   }


Nic Ferrier

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to