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