While insert ing a SQL query we do not specify the auto increment values, if any.插入荷兰SQL查询,我们不指定自动增加值,如果有的话。 However they are often required for further processing.不过,他们往往需要作进一步处理。 Here is how you can obtain auto increment / auto generated values after a successful SQL INSERT statement.在这里,是如何可以获取自动递增/自动产生的价值观后,一个成功的SQL插入声明。

 //     // Insert one row that will generate an AUTO INCREMENT     // key in the primary key field     //     stmt.executeUpdate(             "INSERT INTO autoIncTest (comment) "             + "values ('How can I get the auto increment field value?')",             Statement.RETURN_GENERATED_KEYS);      //     // Use Statement.getGeneratedKeys()     // to retrieve the value(s)     //      int autoIncValue = -1;      rs = stmt.getGeneratedKeys();      if (rs.next()) {         autoIncValue = rs.getInt(1);     } else {          // Error     }      rs.close(); / / / /插入一列,将产生一个自动递增/ /关键在主键字段/ / stmt.executeupdate ( “插入autoinctest (评论) ” + “值( '我怎样才能获得自动递增字段值? ' ) “ , statement.return_generated_keys ) ; / / / /使用statement.getgeneratedkeys ( ) / /检索的价值( ) / /诠释autoincvalue = -1 ;卢比= stmt.getgeneratedkeys ( ) ;如果( rs.next ( ) ) ( autoincvalue = rs.getint ( 1 ) ; )否则( / /错误) rs.close ( ) ; 

You can also specify and fetch multiple auto-increment key values.您也可以指定和市值多个自动增量关键的价值观。 This is not just a convenience but a necessity where the primary key is also the auto increment key.这不仅是方便,而是一种需要的地方,小学的关键,也是自动递增的关键。