Thread

  1. JDBC ResultSet.getObject() fails for type INTERVAL

    PostgreSQL Bugs List <pgsql-bugs@postgresql.org> — 2001-02-02T05:01:33Z

    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
    
    
    
  2. Re: JDBC ResultSet.getObject() fails for type INTERVAL

    Peter T Mount <peter@retep.org.uk> — 2001-02-03T11:27:33Z

    At 00:01 02/02/01 -0500, pgsql-bugs@postgresql.org wrote:
    >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.
    
    This is caused because getObject() can't find the class handling Interval. 
    Probably because there currently isn't one.
    
    When I last checked there was 45 types in 7.1 and I think the JDBC driver 
    has about 1/2 of them mapped to either SQL or a custom class. Shouldn't 
    take too long to implement.
    
    Peter