[ 
https://issues.apache.org/jira/browse/DERBY-5488?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13150563#comment-13150563
 ] 

Knut Anders Hatlen commented on DERBY-5488:
-------------------------------------------

> Can anyone think of a way that a program would fail because of this proposed 
> Derby behavior?

Perhaps a little far-fetched, but this small program works on Java 6 if 
getJDBCMinorVersion() returns 0 and fails if it returns 1:

import java.sql.*;
public class Test {
    public static void main(String[] args) throws SQLException {
        Connection c = 
DriverManager.getConnection("jdbc:derby:memory:db;create=true");

        DatabaseMetaData dmd = c.getMetaData();
        int major = dmd.getJDBCMajorVersion();
        int minor = dmd.getJDBCMinorVersion();

        boolean isAtLeastJDBC41 = (major == 4 && minor >= 1) || major > 4;

        Statement s = c.createStatement();
        ResultSet rs = s.executeQuery("values 1234");
        while (rs.next()) {
            if (isAtLeastJDBC41) {
                Integer i = rs.getObject(1, Integer.class);
                System.out.println("I:" + i);
            } else {
                int i = rs.getInt(1);
                System.out.println("i:" + i);
            }
        }
    }
}

You'll need to compile it with the Java 7 compiler and specify -source 1.6 and 
-target 1.6 to make it run on Java 6.

With minor version = 0 on Java 6:

$ java Test
i:1234

With minor version = 1 on Java 6:

$ java Test
Exception in thread "main" java.lang.NoSuchMethodError: 
java.sql.ResultSet.getObject(ILjava/lang/Class;)Ljava/lang/Object;
        at Test.main(Test.java:16)
                
> Add remaining JDBC 4.1 bits which did not appear in the Java 7 javadoc.
> -----------------------------------------------------------------------
>
>                 Key: DERBY-5488
>                 URL: https://issues.apache.org/jira/browse/DERBY-5488
>             Project: Derby
>          Issue Type: Improvement
>          Components: JDBC, SQL
>    Affects Versions: 10.9.0.0
>            Reporter: Rick Hillegas
>            Assignee: Rick Hillegas
>         Attachments: JDBC_4.1_Supplement.html, 
> derby-5488-01-aa-objectMappingAndConversion.diff, 
> derby-5488-02-aa-fixBigInteger.diff, 
> derby-5488-03-ac-moveDecimalSetterGetterAndTest.diff, 
> derby-5488-04-aa-fixBigIntegerDecimal.diff, 
> derby-5488-05-ad-limitOffset.diff, derby-5488-06-aa-limitOffsetTests.diff, 
> derby-5488-07-aa-booleanObjects.diff, 
> derby-5488-08-aa-extraLimitOffsetTest.diff, 
> derby-5488-09-aa-jdbcMinorVersion.diff, z.java
>
>
> In addition to the JDBC 4.1 bits which were visible in the Java 7 javadoc, a 
> couple other items appear in the JDBC 4.1 Maintenance Review spec. This spec 
> has been published on the JCP website at 
> http://download.oracle.com/otndocs/jcp/jdbc-4_1-mrel-eval-spec/index.html. I 
> will attach a functional spec for the remaining bits.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to