Re: Weird database problem & catching exception

viju <[email protected]>
Newsgroups gmane.comp.java.sun.servlet
Message-ID <006d01c2ccde$1ce0b650$6d00a8c0@viju>
Check the statement if it is null before closing it.

Vj

  ----- Original Message ----- 
  From: Tom Kochanowicz 
  To: [email protected] 
  Sent: Tuesday,February 04,2003 11:43 PM
  Subject: Weird database problem & catching exception


  I am using MySQL with Resin. Recently there has been a lot of discussion on this list about closing database statements and problems. Has anyone run into this one?

   

  I have this finally statement

  finally{

        try{

          // close the statments & DB connection

          insertStatementAdInfoView.close();

          dbConnection.close();

        }catch(Exception e){   // SQLException doesn't work

        System.out.println("Problem with insertStatementAdInfoView " + e);

        }

      }

   

When I catch an SQLException I get a java.lang.NullPointerException and it crashes. When I catch with just Exception, I still get a NullPointerException but the program works! I thought the SQLException should handle this. Why am I getting a NullPointerException (500 Servlet Exception)exception when I am just doing an insert into a database? The insert, inserts the data even with the NullPointerException when catching it with Exception. What could be causing this exception when I am simply using a getParameter to read a jsp entry and doing an insert with a prepared statement?
 
T.K.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.