JDBC ResultSet.getObject() fails for type INTERVAL - Mailing list pgsql-bugs

From pgsql-bugs@postgresql.org
Subject JDBC ResultSet.getObject() fails for type INTERVAL
Date
Msg-id 200102020501.f1251Xr08215@hub.org
Whole thread Raw
Responses Re: JDBC ResultSet.getObject() fails for type INTERVAL  (Peter Mount <peter@retep.org.uk>)
List pgsql-bugs
John Lemcke (jlemcke@netspace.net.au) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
JDBC ResultSet.getObject() fails for type INTERVAL

Long Description
Trying to retrieve an INTERVAL from a ResultSet causes an exception. The following output is from the attached example
code.

~/src/java/rules > java TestInterval
1
string1
TestInterval.executeQuery() : No class found for interval.
TestInterval.main : No class found for interval.
No class found for interval.
        at java.lang.Throwable.fillInStackTrace(Native Method)
        at org.postgresql.Connection.getObject(Connection.java:631)
        at org.postgresql.jdbc2.ResultSet.getObject(ResultSet.java:759)
        at TestInterval.executeQuery(Compiled Code)
        at TestInterval.main(TestInterval.java:70)
~/src/java/rules >

===========================================================

Here id the PostgreSQL version info
test_interval=# select version();
                             version
-----------------------------------------------------------------
 PostgreSQL 7.0.3 on sparc-sun-solaris2.8, compiled by gcc 2.8.1
(1 row)

test_interval=#

JDBC was compiled as jbdc2.

===========================================================

Here is the java version info
~/src/java/rules > java -version
java version "1.2.1"
Solaris VM (build Solaris_JDK_1.2.1_04c, native threads, sunwjit)


Sample Code
///////////////////
//
// TestInterval.java
//
// Demonstrates a bug (I think) in the PostgreSQL JDBC driver
// when handling columns of type interval.
//
///////////////////
//
//  Create the database test_interval using the following SQL
//
//  DROP TABLE test_interval;
//
//  CREATE TABLE test_interval (
//  number1   INT,
//  string1   VARCHAR(8),
//  interval1 INTERVAL
//  );
//
//  INSERT INTO test_interval VALUES (1, 'string1', '12:35');
//  INSERT INTO test_interval VALUES (2, 'string2', '13:00');
//  SELECT * FROM test_interval;
//  -- Show that PostgreSQL does something sensible with INTERVALS
//  SELECT SUM(interval1) FROM test_interval;
//
///////////////////

import java.sql.*;

public class TestInterval {
    Connection          connection;
    Statement           statement;
    ResultSet           resultSet;

    public TestInterval() throws Exception {
        try {
            Class.forName("org.postgresql.Driver");
            connection = DriverManager.getConnection(
                "jdbc:postgresql:test_interval",
                "jlemcke",
                "");
            statement = connection.createStatement();
        }
        catch (ClassNotFoundException ex) {
            System.err.println("Cannot find the database driver classes.");
            System.err.println(ex);
        }
    }

    public void executeQuery(String query)  throws SQLException {
        try {
            resultSet = statement.executeQuery(query);
            while (resultSet.next()) {
                // Get the INT
                System.out.println(resultSet.getObject(1));
                // Get the VARCHAR(8)
                System.out.println(resultSet.getObject(2));
                // Get the INTERVAL
                System.out.println(resultSet.getObject(3));
            }
        }
        catch (SQLException ex) {
            System.err.println("TestInterval.executeQuery() : " + ex);
            throw(ex);
        }
    }

    public static void main(String s[]) {
        try {
            new TestInterval().executeQuery("select * from test_interval");
        }
        catch (Exception ex) {
            System.err.println("TestInterval.main : " + ex);
            ex.printStackTrace();
        }
    }
}


No file was uploaded with this report

pgsql-bugs by date:

Previous
From: Hiroshi Inoue
Date:
Subject: Re: Re: DB crash on "drop table" interruption
Next
From: "And. Andruikhanov"
Date:
Subject: insert char(1) type by different ways.