Re: NullPointer error returned from ResultSet.java
От | Barry Lind |
---|---|
Тема | Re: NullPointer error returned from ResultSet.java |
Дата | |
Msg-id | 3DA59E7C.4010800@xythos.com обсуждение исходный текст |
Ответ на | Re: NullPointer error returned from ResultSet.java ("G.Nagarajan" <gnagarajan@dkf.de>) |
Ответы |
Re: NullPointer error returned from ResultSet.java
|
Список | pgsql-jdbc |
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@postgresql.org >>[mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Jeff Duffy >>Sent: Monday, October 07, 2002 5:57 PM >>To: pgsql-jdbc@postgresql.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@alanne.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 >
В списке pgsql-jdbc по дате отправления: