NullPointerException at org.postgresql.jdbc2.ResultSet.next(ResultSet.java:113) - Mailing list pgsql-jdbc

From Wim Ceulemans
Subject NullPointerException at org.postgresql.jdbc2.ResultSet.next(ResultSet.java:113)
Date
Msg-id 1017313998.14078.25.camel@wc
Whole thread Raw
Responses Re: NullPointerException atorg.postgresql.jdbc2.ResultSet.next(ResultSet.java:113)
List pgsql-jdbc
Hi

I am having problems upgrading my application from postgresql 7.0.2 to
7.2 with the new JDBC driver.

I have managed to produce a small test program that illustrates the
problem. The problem is that in my application I only use one Statement
(a static instance that is never closed), and I re-use that statement to
do all my queries. This worked in the JDBC driver up until 7.0.2.

Now this does not seem to work anymore, I'm not sure if this is a bug or
something I do wrong with respect to the JDBC specs.

The following program works in older JDBC drivers, but now gives the
error as in the subject of my E-mail: (note that I re-use the statement
before I process the result set)

/*
 * @(#)Test1.java
 *
 */

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;

class Test1
{
    private static Connection connection;
    private static String url = "jdbc:postgresql:able";
    private static String driver = "org.postgresql.Driver";
    private static String login = "postgres";
    private static String password = "postgres";
    private static Statement stmt;

    public Test1()
    {
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            System.out.println("ClassNotFoundException: " + e.getMessage());
        }
        try {
            connection = DriverManager.getConnection(url,login,password);
            stmt = connection.createStatement();
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }
        ResultSet resultSet1;
        ResultSet resultSet2;
        try {
            resultSet1 = stmt.executeQuery("select * from tlogicalpart");
            resultSet2 = stmt.executeQuery("select * from tstockpart");
            int row = 0;
            while (resultSet1.next()) {
                System.out.println("row: "+row);
                row++;
            }
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }
    }
    public static void main(String args[])
    {
        new Test1();
    }
}


Regards


Wim Ceulemans



pgsql-jdbc by date:

Previous
From: "Dave Cramer"
Date:
Subject: Re: Error on commi()
Next
From: "Dave Cramer"
Date:
Subject: Re: NullPointerException atorg.postgresql.jdbc2.ResultSet.next(ResultSet.java:113)