[英]How to use a RowId returned from PreparedStatement.getGeneratedKeys()?
I have the code below. 我有下面的代码。 It's a prepared statement with a request to return the generated keys.
这是一条准备好的语句,要求返回生成的密钥。
In the generatedKeys result set, the only return column is named "ROWID" and value is an instance of the RowId
class. 在generateKeys结果集中,唯一的返回列名为“ ROWID”,值是
RowId
类的实例。 See screencap at the bottom. 请参阅底部的屏幕截图。
My question is how to use the row id to get the whole row? 我的问题是如何使用行ID来获取整行?
preparedStatement = conn.prepareStatement(insert, Statement.RETURN_GENERATED_KEYS);
SqlUtils.addParams(preparedStatement, params);
preparedStatement.executeUpdate();
ResultSet generatedKeys = preparedStatement.getGeneratedKeys();
Once I inserted the data, and got the rowid
, I can use it to super fastly extract the whole row, including the generated values that were inserted, for example values inserted by a DB procedure. 插入数据并获得
rowid
,就可以使用它来快速快速提取整行,包括插入的生成值,例如由DB过程插入的值。
Example of using the rowid to extract the row: 使用rowid提取行的示例:
Object rowId = generatedKeys.getObject(1);
String tableName = generatedKeys.getMetaData().getTableName(1);
List<Map<String, Object>> resAsList = select(conn, "select * from " + tableName + " where rowid=?", rowId);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.