Derby
  1. Derby
  2. DERBY-4668

Derby stored procedures with DriverManager.getConnection("jdbc:default:connection") fail if JCC 4.x (db2jcc4.jar) is in the classpath or any version jcc is explicitly loaded

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Invalid
    • Affects Version/s: 10.6.1.0
    • Fix Version/s: None
    • Component/s: Miscellaneous
    • Labels:
      None
    • Environment:
    • Issue & fix info:
      High Value Fix, Repro attached, Workaround attached
    • Bug behavior facts:
      Regression

      Description

      Executing a Derby stored procedure with JCC 4.x in the classpath will error because JCC recognizes the jdbc:default:connection url and tries to make a connection. With JDK 1.6 and JCC 4.x the JCC Driver is autoloaded so simply having it in the classpath can cause the error.

      To reproduce, put db2jcc4.jar in your classpath and run the test, lang.LangProcedureTest which will fail with errors like:
      Caused by: java.lang.ExceptionInInitializerError
      at java.lang.J9VMInternals.initialize(J9VMInternals.java:222)
      at com.ibm.db2.jcc.t2.T2Configuration.<clinit>(T2Configuration.java:78)
      at java.lang.J9VMInternals.initializeImpl(Native Method)
      at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
      at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:420)
      at java.sql.DriverManager.getConnection(DriverManager.java:317)
      at java.sql.DriverManager.getConnection(DriverManager.java:273)
      at org.apache.derbyTesting.functionTests.tests.lang.LangProcedureTest.DERBY_3304(LangProcedureTest.java:287)
      at org.apache.derby.exe.ac05550069x0128xb447xd1b2x00002461cbf40.g0(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:600)
      at org.apache.derby.impl.services.reflect.ReflectMethod.invoke(ReflectMethod.java:46)
      at org.apache.derby.impl.sql.execute.CallStatementResultSet.open(CallStatementResultSet.java:75)
      at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(GenericPreparedStatement.java:436)
      at org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPreparedStatement.java:317)
      at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1232)
      at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:625)
      at org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(EmbedStatement.java:152)
      at org.apache.derbyTesting.functionTests.tests.lang.LangProcedureTest.testMethodSignatureDerby258(LangProcedureTest.java:268)
      ... 23 more
      Caused by: java.security.AccessControlException: Access denied (java.util.PropertyPermission * read,write)
      at java.security.AccessControlException.<init>(AccessControlException.java:62)
      at java.security.AccessController.checkPermission(AccessController.java:68)
      at java.lang.SecurityManager.checkPermission(SecurityManager.java:533)
      at java.lang.SecurityManager.checkPropertiesAccess(SecurityManager.java:1253)
      at java.lang.System.getProperties(System.java:323)
      at com.ibm.db2.jcc.am.md.run(md.java:37)
      at java.security.AccessController.doPrivileged(AccessController.java:202)
      at com.ibm.db2.jcc.t2.c.<clinit>(c.java:38)
      at java.lang.J9VMInternals.initializeImpl(Native Method)
      at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
      ... 43 more
      used 109 ms .
      testParameterTypes used 188 ms E.
      testOutparams used 94 ms .
      testSQLControl used 234 ms E.
      testCreateRoutineErrors used 203 ms .
      testMethodSignatureDerby258 used 203 ms E.
      testDelayedClassChecking used 32 ms .
      testDuplicates used 171 ms .
      testAmbigiousMethods used 157 ms E.
      testZeroArgProcedures used 31 ms .
      testSqlProcedures used 203 ms E.
      testDynamicResultSets used 203 ms E.
      testResultSetsWithLobs FAIL: Encountered exception:
      java.sql.SQLException: The exception 'java.lang.NoClassDefFoundError: com.ibm.db2.jcc.t2.T2Configuration (initialization failure)' was thrown while evaluating an expression.
      at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:96)
      at org.apache.derby.client.am.SqlException.getSQLException(SqlException.java:358)
      at org.apache.derby.client.am.PreparedStatement.execute(PreparedStatement.java:1574)
      at org.apache.derbyTesting.functionTests.tests.lang.LangProcedureTest.testResultSetsWithLobs(LangProcedureTest.java:899)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:600)
      at junit.framework.TestCase.runTest(TestCase.java:154)
      at junit.framework.TestCase.runBare(TestCase.java:127)
      at org.apache.derbyTesting.junit.BaseTestCase.runBare(BaseTestCase.java:109)
      at junit.framework.TestResult$1.protect(TestResult.java:106)
      at junit.framework.TestResult.runProtected(TestResult.java:124)
      at junit.framework.TestResult.run(TestResult.java:109)
      at junit.framework.TestCase.run(TestCase.java:118)
      at junit.framework.TestSuite.runTest(TestSuite.java:208)
      at junit.framework.TestSuite.run(TestSuite.java:203)
      at junit.extensions.TestDecorator.basicRun(TestDecorator.java:22)
      at junit.extensions.TestSetup$1.protect(TestSetup.java:19)
      at junit.framework.TestResult.runProtected(TestResult.java:124)
      at junit.extensions.TestSetup.run(TestSetup.java:23)
      at org.apache.derbyTesting.junit.BaseTestSetup.run(BaseTestSetup.java:57)
      at junit.extensions.TestDecorator.basicRun(TestDecorator.java:22)
      at junit.extensions.TestSetup$1.protect(TestSetup.java:19)
      at junit.framework.TestResult.runProtected(TestResult.java:124)
      at junit.extensions.TestSetup.run(TestSetup.java:23)
      at junit.extensions.TestDecorator.basicRun(TestDecorator.java:22)
      at junit.extensions.TestSetup$1.protect(TestSetup.java:19)
      at junit.framework.TestResult.runProtected(TestResult.java:124)
      at junit.extensions.TestSetup.run(TestSetup.java:23)
      at org.apache.derbyTesting.junit.BaseTestSetup.run(BaseTestSetup.java:57)
      at junit.framework.TestSuite.runTest(TestSuite.java:208)
      at junit.framework.TestSuite.run(TestSuite.java:203)
      at junit.textui.TestRunner.doRun(TestRunner.java:116)
      at junit.textui.TestRunner.start(TestRunner.java:172)
      at junit.textui.TestRunner.main(TestRunner.java:138)

      I will post a smaller reproduction.

      I think JCC needs to be smarter about it's context and avoid hijacking the connection when not running inside a DB2 stored procedure. The problem can also with previous JCC versions if the driver is explicitly loaded. Autoloading aggravates the problem and may regress Derby users when they upgrade their JCC. The DERBY-4664 fix will mitigate the issue for internal procedures but does not solve the problem for user procedures. I think the fix will have to come from JCC but am filing it here as it may impact users.

      One workaround would be to remove JCC from the classpath if possible.

      1. Repro4668.java
        1 kB
        Kathey Marsden

        Activity

        Hide
        Knut Anders Hatlen added a comment -

        If I understand this issue correctly, we'll see the problem regardless of Derby version. Should we remove the regression flag?

        I agree with the analysis that the fix will have to be come from JCC. Derby does check if it's running inside another Derby connection before it returns a connection for jdbc:default:connection. If JCC did the same, we would probably not have this problem.

        Show
        Knut Anders Hatlen added a comment - If I understand this issue correctly, we'll see the problem regardless of Derby version. Should we remove the regression flag? I agree with the analysis that the fix will have to be come from JCC. Derby does check if it's running inside another Derby connection before it returns a connection for jdbc:default:connection. If JCC did the same, we would probably not have this problem.
        Hide
        Myrna van Lunteren added a comment -

        If it's not something actually wrong in derby, perhaps this should be closed as 'invalid'?
        It's been logged so users can find it; there's an explanation here and the 'workaround' is documented here...
        (Otherwise, this'll stay open and 'critical' forever).

        Show
        Myrna van Lunteren added a comment - If it's not something actually wrong in derby, perhaps this should be closed as 'invalid'? It's been logged so users can find it; there's an explanation here and the 'workaround' is documented here... (Otherwise, this'll stay open and 'critical' forever).
        Hide
        Kathey Marsden added a comment -

        Thanks Myrna, that is a good point.

        I am going to work for a bit to get a more complete filing of the issue with a smaller reproduction, do some experiments and see if I can come up with a workaround that does not involve changing the classpath. I will keep it open for maybe a week for this purpose and then close Invalid as you suggest.

        Show
        Kathey Marsden added a comment - Thanks Myrna, that is a good point. I am going to work for a bit to get a more complete filing of the issue with a smaller reproduction, do some experiments and see if I can come up with a workaround that does not involve changing the classpath. I will keep it open for maybe a week for this purpose and then close Invalid as you suggest.
        Hide
        Kathey Marsden added a comment -

        Attached is a Reproduction for this issue Repro4668. If I put db2jcc4.jar in my classpath it fails because the JCC driver takes the connection away from the Derby stored procedure before the Derby drier sees it:
        javac -d . -g Repro4668.java

        $ java com.mycode.Repro4668
        Exception in thread "main" java.sql.SQLException: The exception 'com.ibm.db2.jcc
        .am.SqlException: [jcc][10216][11231][4.11.29] Required property "databaseName"
        is not set. ERRORCODE=-4462, SQLSTATE=null' was thrown while evaluating an expre
        ssion.
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(SQLE
        xceptionFactory40.java:95)
        at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Util.java:142)
        at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:278)
        at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException
        (TransactionResourceImpl.java:398)
        at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Tr
        ansactionResourceImpl.java:346)
        at org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConne
        ction.java:2269)
        at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Connection
        Child.java:81)
        at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedState
        ment.java:1321)
        at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java
        :625)
        at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java
        :555)
        at com.mycode.Repro4668.main(Repro4668.java:27)
        Caused by: java.sql.SQLException: The exception 'com.ibm.db2.jcc.am.SqlException
        : [jcc][10216][11231][4.11.29] Required property "databaseName" is not set. ERRO
        RCODE=-4462, SQLSTATE=null' was thrown while evaluating an expression.
        at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExc
        eptionFactory.java:45)
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransport
        AcrossDRDA(SQLExceptionFactory40.java:119)
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(SQLE
        xceptionFactory40.java:70)
        ... 10 more
        Caused by: com.ibm.db2.jcc.am.SqlException: [jcc][10216][11231][4.11.29] Require
        d property "databaseName" is not set. ERRORCODE=-4462, SQLSTATE=null
        at com.ibm.db2.jcc.am.fd.a(fd.java:660)
        at com.ibm.db2.jcc.am.fd.a(fd.java:60)
        at com.ibm.db2.jcc.am.fd.a(fd.java:103)
        at com.ibm.db2.jcc.uw.UWConnection.Md(UWConnection.java:353)
        at com.ibm.db2.jcc.uw.UWConnection.<init>(UWConnection.java:271)
        at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource
        .java:220)
        at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:456)
        at java.sql.DriverManager.getConnection(DriverManager.java:317)
        at java.sql.DriverManager.getConnection(DriverManager.java:273)
        at com.mycode.Repro4668.myproc(Repro4668.java:39)
        at org.apache.derby.exe.acf81e0010x0128xb6f7xc8f5x0000002a48300.g0(Unkno
        wn Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
        java:48)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
        sorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:600)
        at org.apache.derby.impl.services.reflect.ReflectMethod.invoke(ReflectMe
        thod.java:46)
        at org.apache.derby.impl.sql.execute.CallStatementResultSet.open(CallSta
        tementResultSet.java:75)
        at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Generi
        cPreparedStatement.java:436)
        at org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPre
        paredStatement.java:317)
        at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedState
        ment.java:1232)
        ... 3 more

        kmarsden@IBM-93AE43E63C0 ~/repro/derby-4668
        $

        The expected output and output without db2jcc4.jar in the claspath is:

        $ java com.mycode.Repro4668

          • Start stored procedure. Default Connection:Apache Derby
            MYPROC visits:
            2010-05-20 11:26:07.64
        Show
        Kathey Marsden added a comment - Attached is a Reproduction for this issue Repro4668. If I put db2jcc4.jar in my classpath it fails because the JCC driver takes the connection away from the Derby stored procedure before the Derby drier sees it: javac -d . -g Repro4668.java $ java com.mycode.Repro4668 Exception in thread "main" java.sql.SQLException: The exception 'com.ibm.db2.jcc .am.SqlException: [jcc] [10216] [11231] [4.11.29] Required property "databaseName" is not set. ERRORCODE=-4462, SQLSTATE=null' was thrown while evaluating an expre ssion. at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(SQLE xceptionFactory40.java:95) at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Util.java:142) at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:278) at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException (TransactionResourceImpl.java:398) at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Tr ansactionResourceImpl.java:346) at org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConne ction.java:2269) at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Connection Child.java:81) at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedState ment.java:1321) at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java :625) at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java :555) at com.mycode.Repro4668.main(Repro4668.java:27) Caused by: java.sql.SQLException: The exception 'com.ibm.db2.jcc.am.SqlException : [jcc] [10216] [11231] [4.11.29] Required property "databaseName" is not set. ERRO RCODE=-4462, SQLSTATE=null' was thrown while evaluating an expression. at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExc eptionFactory.java:45) at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransport AcrossDRDA(SQLExceptionFactory40.java:119) at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(SQLE xceptionFactory40.java:70) ... 10 more Caused by: com.ibm.db2.jcc.am.SqlException: [jcc] [10216] [11231] [4.11.29] Require d property "databaseName" is not set. ERRORCODE=-4462, SQLSTATE=null at com.ibm.db2.jcc.am.fd.a(fd.java:660) at com.ibm.db2.jcc.am.fd.a(fd.java:60) at com.ibm.db2.jcc.am.fd.a(fd.java:103) at com.ibm.db2.jcc.uw.UWConnection.Md(UWConnection.java:353) at com.ibm.db2.jcc.uw.UWConnection.<init>(UWConnection.java:271) at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource .java:220) at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:456) at java.sql.DriverManager.getConnection(DriverManager.java:317) at java.sql.DriverManager.getConnection(DriverManager.java:273) at com.mycode.Repro4668.myproc(Repro4668.java:39) at org.apache.derby.exe.acf81e0010x0128xb6f7xc8f5x0000002a48300.g0(Unkno wn Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:48) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:600) at org.apache.derby.impl.services.reflect.ReflectMethod.invoke(ReflectMe thod.java:46) at org.apache.derby.impl.sql.execute.CallStatementResultSet.open(CallSta tementResultSet.java:75) at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Generi cPreparedStatement.java:436) at org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPre paredStatement.java:317) at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedState ment.java:1232) ... 3 more kmarsden@IBM-93AE43E63C0 ~/repro/derby-4668 $ The expected output and output without db2jcc4.jar in the claspath is: $ java com.mycode.Repro4668 Start stored procedure. Default Connection:Apache Derby MYPROC visits: 2010-05-20 11:26:07.64
        Hide
        Kathey Marsden added a comment -

        I neglected to mention. The db2jcc4.jar file can be downloaded from :

        http://www-01.ibm.com/support/docview.wss?rs=71&uid=swg27007053

        Go into DB2 9.7 FP1 -> Your platform --> BM Data Server Driver for JDBC and SQLJ

        As an aside, I would be interested to hear if having db2jcc4.jar in the system classpath interferes with other database products' stored procedures if it is in the system classpath.

        Show
        Kathey Marsden added a comment - I neglected to mention. The db2jcc4.jar file can be downloaded from : http://www-01.ibm.com/support/docview.wss?rs=71&uid=swg27007053 Go into DB2 9.7 FP1 -> Your platform --> BM Data Server Driver for JDBC and SQLJ As an aside, I would be interested to hear if having db2jcc4.jar in the system classpath interferes with other database products' stored procedures if it is in the system classpath.
        Hide
        Kathey Marsden added a comment -

        The following really ugly workaround seems to work even with authentication. Instead of DriverManager.getConnection, I used DriverManager.getDriver to make sure I pick up the Derby driver and then connect,.

        Connection conn = DriverManager.getDriver("jdbc:derby:default").connect("jdbc:default:connection",new Properties());

        Show
        Kathey Marsden added a comment - The following really ugly workaround seems to work even with authentication. Instead of DriverManager.getConnection, I used DriverManager.getDriver to make sure I pick up the Derby driver and then connect,. Connection conn = DriverManager.getDriver("jdbc:derby:default").connect("jdbc:default:connection",new Properties());
        Hide
        Kathey Marsden added a comment -

        Closing invalid since this looks like a JCC bug. JCC needs to recognize that they are not in a DB2 stored procedure context when evaluating the jdbc:default:connection url.

        Show
        Kathey Marsden added a comment - Closing invalid since this looks like a JCC bug. JCC needs to recognize that they are not in a DB2 stored procedure context when evaluating the jdbc:default:connection url.

          People

          • Assignee:
            Unassigned
            Reporter:
            Kathey Marsden
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development