ext*_*eon 53
复制自我的代码:
pInsertOid = connection.prepareStatement(INSERT_OID_SQL, Statement.RETURN_GENERATED_KEYS);
Run Code Online (Sandbox Code Playgroud)
其中pInsertOid是一个预准备语句.
然后你可以获得密钥:
// fill in the prepared statement and
pInsertOid.executeUpdate();
ResultSet rs = pInsertOid.getGeneratedKeys();
if (rs.next()) {
int newId = rs.getInt(1);
oid.setId(newId);
}
Run Code Online (Sandbox Code Playgroud)
希望这能为您提供一个良好的起点.
atr*_*thi 23
extraneon的答案虽然正确,但对甲骨文不起作用.
您为Oracle执行此操作的方式是:
String key[] = {"ID"}; //put the name of the primary key column
ps = con.prepareStatement(insertQuery, key);
ps.executeUpdate();
rs = ps.getGeneratedKeys();
if (rs.next()) {
generatedKey = rs.getLong(1);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39098 次 |
| 最近记录: |