1 2 Previous Next 19 Replies Latest reply: Nov 6, 2013 1:01 PM by dsurber RSS

    NullPointerException with s.getGeneratedKeys().getMetaData() [12.1.0.1.0]

    natros

      This code fails with ojdbc6 12.1.0.1.0 when getting meta data from a generated key. The same code works with ojdbc6 11.2.0.3.0


      The same happens with ojdbc7 and ojdbc7_g


      @Test

      public void testInsertPk() throws Exception {

        Connection con = null;

        PreparedStatement s = null;

        ResultSet r = null;

         try {

        con = ds.getConnection();

       

        String[] pk = { "candidatura_id" };

        s = con.prepareStatement("INSERT INTO candidatura(cod_aluno, aluno_ipb, user_id) VALUES(?, ?, ?)", pk);

        s.setInt(1, 13444);

        s.setBoolean(2, true);

        s.setInt(3, 111);

        assertThat(s.executeUpdate(), is(1));

        r = s.getGeneratedKeys();

        assertThat(r.next(), is(true));

        ResultSetMetaData md = r.getMetaData();

        assertThat(md, notNullValue());

        assertThat(md.getColumnCount(), is(1));

        assertThat(md.getColumnName(1), equalTo(pk[0].toUpperCase()));

        } finally {

        close(r, s, con);

        }

      }

       

      java.lang.NullPointerException

        at oracle.jdbc.driver.AutoKeyInfo.initMetaDataColumnIndexes(AutoKeyInfo.java:423)

        at oracle.jdbc.driver.AutoKeyInfo.initMetaData(AutoKeyInfo.java:396)

        at oracle.jdbc.driver.OracleReturnResultSet.getMetaData(OracleReturnResultSet.java:77)

        at pt.ipb.creditacao.server.sql.DatabaseTest.testInsertPk(DatabaseTest.java:67)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)

        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)

        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)

        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)

        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)

        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)

        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

        at org.junit.runner.JUnitCore.run(JUnitCore.java:160)

        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)

        at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)

        at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)


      $ cat /etc/centos-release

      CentOS release 6.4 (Final)

       

      $ arch

      x86_64

       

      $ java -version

      java version "1.7.0_25"

      Java(TM) SE Runtime Environment (build 1.7.0_25-b15)

      Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)


      Database: Oracle/Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production

      With the Partitioning, OLAP and Real Application Testing options


      Thanks,

      Filipe Sousa

        1 2 Previous Next