List:General Discussion« Previous MessageNext Message »
From:Christian Mack Date:September 10 1999 6:33pm
Subject:Re: Fw: unable to execute query in while loop
View as plain text  
Sajida Kalsoom wrote:
> 
> ----- Original Message -----
> From: Sajida Kalsoom
> To: Mysql
> Sent: Wednesday, September 08, 1999 10:18 AM
> Subject: unable to execute query in while loop
> 
> Dear Users,
> 
>     I am working on mysql 3.22.23 version on solaris, at backend and servlets at
> front end . I am trying to execute query which is 'select query' in loop first time querry
> is executed well but when loop evaluates second time it give me following error
> 
> java.lang.NullPointerException
> at org.gjt.mm.mysql.ResultSet.close(Compiled Code)
> at org.gjt.mm.mysql.Statement.executeQuery(Compiled Code)
> at DOBillCharges1.doPost(Compiled Code)
> at javax.servlet.http.HttpServlet.service(Compiled Code)
> at javax.servlet.http.HttpServlet.service(Compiled Code)
> at org.apache.jserv.JServConnection.processRequest(Compiled Code)
> at org.apache.jserv.JServConnection.run(Compiled Code)
> at java.lang.Thread.run(Compiled Code)
> 
> my codes is looks like this
> ...
> ....
> ...
> ConnectionPool pool=new ConnectionPool();
> 
> ....
> boolean flag;
> conn = pool.getConnection();
> stmt=conn.createStatement();
> 
> keys = req.getParameterNames(); // gets form parameter names
> 
> while (keys.hasMoreElements())
> {
> key = (String) keys.nextElement();
> value = req.getParameter(key);
> 
> sql="Select HeadName from TblChargesHeads where HeadID="+key;
> rs=stmt.executeQuery(sql);
> out.println(sql);
> flag = rs.next();
> if(flag)
> {
> 
> HeadName=rs.getString("HeadName");
> 
> }
> 
> }
> 
> would some like to tell me whats wrong , I will be so thankful to him.

Hi Sajida

You should alway explicitely close each ResultSet when not used anymore.
Insert in the while loop after the "if(flag){}" part:
    rs.close();

Hope this helps.
Christian

Thread
Fw: unable to execute query in while loopSajida Kalsoom8 Sep
  • Re: Fw: unable to execute query in while loopChristian Mack10 Sep
  • [mySQL] ERROR 1121: problem with ID variabled e l   d h a n o a10 Sep
    • Re: [mySQL] ERROR 1121: problem with ID variableBenjamin Pflugmann10 Sep
Re: [mySQL] ERROR 1121: problem with ID variableBenjamin Pflugmann11 Sep