2 Replies Latest reply on Apr 25, 2003 9:21 AM by wesyah234

    problem gettting generated keys / autoincrement field

    wesyah234

      If there is a better forum for this question, please let me know.

      I just came across a feature of JDBC where you can (apparently) get back the generated key / autoincrement field that was used for your insert into the db.

      using the following:
      PreparedStatement statement = conn.prepareStatement("insert into table (field) values (?)", Statement.RETURN_GENERATED_KEYS);
      ...

      But when I run this code in jboss/jetty, I get the following exception on the prepareStatement call:
      java.sql.SQLException: JDK1.4 method not available in JDK1.3
      at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:302)
      at
      ...
      -----------------
      I located the source and found were the exception is created:
      WrappedConnection.jpp:
      public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
      {
      @JDK1.4START@
      checkStatus();
      try
      {
      return new WrappedPreparedStatement(this, mc.getConnection().prepareStatement(sql, autoGeneratedKeys));
      }
      catch (SQLException e)
      {
      checkException(e);
      return null;
      } // end of try-catch
      @JDK1.4END@
      @JDK1.3START@
      throw new SQLException("JDK1.4 method not available in JDK1.3");
      @JDK1.3END@
      }

      Also found the ant build file for jboss/connector... apparently it does global search and replace operations on the .jpp sources, once for jdbc2 and once for jdbc3. It seems to be commenting or uncommenting the throw of the exceptions.

      Beyond that, I'm stuck... I don't understand how jboss determines which version of the generated java files to run.

      I'm definitely using jdk1.4, I added an echo of JAVA_HOME to the top of run.bat, and it showed C:\j2sdk1.4.0_01

      I'm using:
      jboss 3.2
      mysql (mysql-connector-java-3.0.6-stable-bin.jar)


      Thanks,
      Wes

        • 1. Re: problem gettting generated keys / autoincrement field

          It sounds like the version of jboss you have
          was compiled with jdk1.3

          You can get a copy from cvs and compile for 1.4

          e.g.
          cvs co ... -r JBoss_3_2_0 branch-3.2

          will get you jboss-3.2.0

          You then do
          cd build
          ./build.sh or build.bat

          The distribution will be created in the output folder.

          Regards,
          Adrian

          • 2. Re: problem gettting generated keys / autoincrement field
            wesyah234

            Thanks.

            I tried downloading from cvs at home, but it would not build (I'm using Windows Me..) And at work, I could not get connected to the cvs repository - I'm assuming the firewall is blocking it.

            The version of Jboss I'm using is the standard 3.2.0 binary download dated 4/11.

            Would it be possible to provide a compiled version for JDK1.4 as well?