Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Generating the next sequential key...

Re: Generating the next sequential key...

From: <stevedhoward_at_gmail.com>
Date: 2 May 2006 08:08:03 -0700
Message-ID: <1146582483.497831.250020@j73g2000cwa.googlegroups.com>


I'm not sure if this is what you are asking, since you referenced getting the _child_ key, but you should be able to do the following to get the key (autonumber in Access) from JDBC. AFAIK, the JDBC bridge to ODBC still doesn't support getGeneratedKeys()...

C:\SCRIPTS\java>type msAccessKey.java
import java.sql.*;

public class msAccessKey {
  public static void main(String args []) {     String dataSourceName = "t0501";
    String dbURL = "jdbc:odbc:" + dataSourceName;     try {

      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection con = DriverManager.getConnection(dbURL, "","");
      Statement stm = con.createStatement();
      stm.executeUpdate("insert into t0501(textval) values('test')");
      int pk = -1;
      ResultSet rs = stm.executeQuery("SELECT @@IDENTITY");
      while (rs.next()) {
        pk = rs.getInt(1);
      }
      System.out.println(pk);
      con.commit();
      con.close();

}

    catch (Exception err) {
      System.out.println(err);
}

  }
}
C:\SCRIPTS\java>javac msAccessKey.java

C:\SCRIPTS\java>java msAccessKey
1

C:\SCRIPTS\java>java msAccessKey
2

C:\SCRIPTS\java>java msAccessKey
3

C:\SCRIPTS\java>java msAccessKey
4

Regards,

Steve Received on Tue May 02 2006 - 10:08:03 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US