日期:2014-05-20 浏览次数:21027 次
String sql = "INSERT INTO tbl (col) VALUES (?)"; preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); preparedStatement.setString(1, col); preparedStatement.executeUpdate(); generatedKeys = preparedStatement.getGeneratedKeys(); if (generatedKeys.next()) { long id = generatedKeys.getLong(1); } else { // Throw exception? }