......
ResultSet rs =stmt.executeQuery("select @@identity");
int nId=0;
if (rs.next())
    nId=rs.getInt(1);

解决方案 »

  1.   

    select max(id),思路是这样,语法自己看看吧。
      

  2.   

    用函数返回一个不就行了吗
    insert into table(id) values(XXX);
    return XXX
      

  3.   

    select @@identity 在DB2中可以吗?还是JDBC内有函数?
      

  4.   

    在jdbc2中就用事务好了,
    conn.setAutoCommit(false);
    insert into tableName
    select max(uniqueidentifier) from tableName;
    conn.setAutoCommit(true);
    在jdbc3中的特性:
    Statement stmt = conn.createStatement();
    stmt.executeUpdate("INSERT INTO authors (first_name, last_name) " +"VALUES ('George', 'Orwell')",Statement.RETURN_GENERATED_KEYS); ResultSet rs = stmt.getGeneratedKeys();
    if ( rs.next() ) {
        // Retrieve the auto generated key(s).    int key = rs.getInt();}