Re: NullPointer error returned from ResultSet.java

From: "G(dot)Nagarajan" <gnagarajan(at)dkf(dot)de>
To: "Barry Lind" <barry(at)xythos(dot)com>
Cc: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: NullPointer error returned from ResultSet.java
Date: 2002-10-10 15:49:10
Message-ID: NFBBIOPECKPCJJHHBOGJKEAADJAA.gnagarajan@dkf.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi Barry,
You had already answered the question, sorry for not posting a follow up:).

Since the function calls itself, there will more than one resultset open. I
modified
the code to get the list into a vector before recursing. Then I used the
vector
rather than moving through the resultset. In this case there will be only
resultset open
at any time and the error doesn't come.

Thanks,
Nagarajan.

> -----Original Message-----
> From: Barry Lind [mailto:barry(at)xythos(dot)com]
> Sent: Thursday, October 10, 2002 5:36 PM
> To: G.Nagarajan
> Cc: pgsql-jdbc(at)postgresql(dot)org
> Subject: Re: [JDBC] NullPointer error returned from ResultSet.java
>
>
> Nagarajan,
>
> If you submit a complete test case that demonstrates the problem I would
> be willing to look into this. But there just isn't enough information
> in what you have provided here to debug this. I don't even know the
> exact error you are getting.
>
> thanks,
> --Barry
>
>
>
> G.Nagarajan wrote:
> > Hi,
> > I am also getting the same error. In my case I am using a prepared
> statement
> > to create the resultset like
> >
> > PreparedStatemet stmt = "...";
> >
> > callerFunction()
> > {
> > createPreparedStatement();
> > fun1();
> > closePreparedStatement();
> > }
> > fun1()
> > {
> > Results rs = stmt.executeQuery();
> >
> > while (rs.next() )
> > {
> > fun1(); //recursive call
> > }
> > rs.close();
> > }
> >
> > The null pointer exception is throws after three recursive calls. The
> code
> > at
> > 113 is rows.size(). Perhaps it has something to do with caching? The
> error
> > doesn't come if I use normal statements.
> >
> > Regards,
> > Nagarajan.
> >
> >
> >
> >>-----Original Message-----
> >>From: pgsql-jdbc-owner(at)postgresql(dot)org
> >>[mailto:pgsql-jdbc-owner(at)postgresql(dot)org]On Behalf Of Jeff Duffy
> >>Sent: Monday, October 07, 2002 5:57 PM
> >>To: pgsql-jdbc(at)postgresql(dot)org
> >>Subject: [JDBC] NullPointer error returned from ResultSet.java
> >>
> >>
> >>Greetings,
> >>
> >> I have a JSP page with a rather large scriptlet that uses multiple
> nested
> >>statements and ResultSets. Under very specific conditions I am
> >>encountering
> >>the following error:
> >>
> >>java.lang.NullPointerException
> >> at org.postgresql.jdbc2.ResultSet.next(ResultSet.java:113)
> >>
> >>
> >>Here's one pertinent snippet of my code:
> >>( This code begins inside a while(rs.next()) loop for ResultSet rs,
> >>using Statement stmt)
> >>
> >>
> >>sql.append("AN SQL QUERY");
> >>rs2 = stmt2.executeQuery(sql.toString());
> >>
> >>while(rs2.next()){
> >> String courseId = rs2.getString(1);
> >> String roleName = rs2.getString(2);
> >>
> >> rs3 = stmt3.executeQuery("SELECT nextval('assignment_id')");
> >> rs3.next();
> >> assignmentId = rs3.getString(1);
> >>
> >> sql.delete(0, sql.length());
> >> sql.append("AN SQL QUERY");
> >> stmt3.executeUpdate(sql.toString());
> >>}
> >>
> >> Through debugging it appears that rs2 is throwing the error;
> the message
> >>states the error is in method next(), but if I have only zero
> records or
> >>only one record in rs2, there is no error. It's only when I
> have multiple
> >>records that the error is thrown the second time round the while
> >>loop, so I
> >>suspect it may be thrown at the assignment of courseId.
> >>
> >> This error is reproduced given the same conditions (nested
> >>ResultSets with
> >>the innermost ResultSet executing an Update inside a
> >>while(ResultSet.next())
> >>loop. It almost seems that the call to rs3.executeUpdate() is
> >>closing rs2,
> >>but I cannot see why that would happen. This is occurring in
> at least six
> >>different source files.
> >>
> >> If I create a new Vector and stuff the contents of rs2 into it, then
> >>iterate over the vector and use rs3 as shown above, no error is thrown.
> >>
> >> Updating to the 7.3beta1 JDBC driver changes the error message to:
> >>
> >>javax.servlet.ServletException: postgresql.con.closed
> >>
> >> which is even more puzzling.
> >>
> >>
> >> Notes about my coding style that may be relevant:
> >>- I use one StringBuffer for all sql queries and clear it for
> >>each new query
> >>for efficiency. This hasn't ever caused problems elsewhere.
> >>
> >>- I predeclare all Statement and ResultSet objects at the
> >>outermost block of
> >>code (the 'top') like so:
> >>
> >>Statement stmt = conn.createStatement();
> >>Statement stmt2 = conn.createStatement();
> >>Statement stmt3 = conn.createStatement();
> >>ResultSet rs, rs2, rs3;
> >>
> >>Other data:
> >>
> >>- The connections are obtained from a custom class that uses
> the jdbcpool
> >>pool manager.
> >>- I'm using the Sun JDK v1.4.0 for Linux (it happens on Win32 as well).
> >>- The JDBC library is v7.2 (the pgjdbc2.jar binary download).
> >>- PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC 2.96
> >>
> >> Any flashes of insight?
> >>
> >>Thanks
> >>
> >>Jeff Duffy
> >>jeff(at)alanne(dot)com
> >>
> >>
> >>---------------------------(end of
> broadcast)---------------------------
> >>TIP 6: Have you searched our list archives?
> >>
> >>http://archives.postgresql.org
> >
> >
> >
> > ---------------------------(end of
> broadcast)---------------------------
> > TIP 6: Have you searched our list archives?
> >
> > http://archives.postgresql.org
> >
>
>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Alexaki Sofia 2002-10-10 16:16:07 Time type error
Previous Message Barry Lind 2002-10-10 15:36:28 Re: NullPointer error returned from ResultSet.java