| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.server -> Re: Generating the next sequential key...
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();
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
![]() |
![]() |