thanks, Ted.

but, I didn't override the init method in this servlet... I just didn't
register this servlet with the jsdk2.1 server... so it wasn't actually
loaded to the server, I guess that's the reason that I can't find the config
object from this servlet...

well, I guess this "servlet" doesn't have to be a servlet... I'm considering
to make it a "helper class" -- (is that the right word?:)

btw, the problem has nothing to do with the PreparedStatement, it's the log
statement in the catch block that caused the problem because of the wrong
settings in the database by our DBA... I commented out the log statement for
now...

----Original Message Follows----
From: Ted Stockwell <[EMAIL PROTECTED]>

I'd bet the problem is that your servlet overrides the init method but
doesn't call super.init().
Your servlet's init method should look like this...
public void init(ServletConfig config) throws ServletException {
         super.init(config);
         ...your stuff here...
}
The 2nd time through the loop a SQLException is thrown and the resulting
call to the log method causes the NullPointerException.

ted stockwell

 > -----Original Message-----
 > From: Papaya Head [SMTP:[EMAIL PROTECTED]]
 > Sent: Tuesday, May 04, 1999 10:41 AM
 > To:   [EMAIL PROTECTED]
 > Subject:      problem with using a PreparedStatement more than once
 >
 > I couldn't figure out what's the problem with the following code...
 > anybody
 > could kindly help with this? Thanks!
 >
 > the problem always happens when the second time I call
 > pstmt.executeUpdate()...
 >
 >         try {
 >             PreparedStatement pstmt = con.prepareStatement(stmt);
 >
 >             for (int i = 0; i < 7; i++) {
 >                 if (hours[i] != 0) {
 >                     // some unrelevant code here...
 >                     pstmt.clearParameters();
 >                     pstmt.setDate(1, Date.valueOf(str_day));
 >                     pstmt.setFloat(2, hours[i]);
 >
 >                     pstmt.executeUpdate();
 >                 } // end of if (hours[i] != 0)
 >             } // end of for loop
 >
 >             pstmt.close();
 >             con.commit();
 >         }
 >         catch (SQLException e) {
 >             log("Exception while updating time_mst: " + e.getMessage());
 >             con.rollback();
 >             throw e;
 >         }
 >
 >
 > The error messages I got are as follows:
 >
 > Error: 500
 >
 >                               Internal Servlet Error:
 >
 >                         java.lang.NullPointerException
 >            at javax.servlet.GenericServlet.getServletContext(Compiled
 > Code)
 >                   at javax.servlet.GenericServlet.log(Compiled Code)
 >                       at DBConPool.insertTimeDet(Compiled Code)
 >
 >
 > _______________________________________________________________
 > Get Free Email and Do More On The Web. Visit http://www.msn.com
 >
 >
__________________________________________________________________________
 > _
 > 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

___________________________________________________________________________
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



_______________________________________________________________
Get Free Email and Do More On The Web. Visit http://www.msn.com

___________________________________________________________________________
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