JDBC Explain 中的 RowId 对象是什么?
jdbcjava 8programmingobject oriented programming更新于 2024/11/2 11:24:17
RowId 是 SQL 的内置类型,表示数据库表中某一行的地址。java.sql 包中的 RowId 接口与 SQL 的 ROWID 值相对应。
RowId 值对于每一行都是唯一的,它们是访问行数据的最快方式。您不能将其用作表的主键。
检索 RowId 对象
您可以使用 ResultSet、CallableStatement 和 PreparedStatement 接口的 getRowId() 方法检索特定行的 RowId。
此方法接受表示列标签的字符串值或表示列索引的整数值,并返回相应的 RowId 对象。
//检索 RowId 对象
RowId rowId1 = rs.getRowId("Mobile_Brand");
RowId rowId2 = rs.getRowId("Unit_Sale");
将 RowId 值设置为预处理语句
您可以将其用作表示每一行的唯一值。您可以使用 setRowId() 方法将其设置为 PreparationStatement 中的参数。您需要向此方法传递一个整数,该整数表示需要将 RowId 设置为值的参数索引。
RowId rowid = rs.getRowId("Mobile_Brand");
PreparedStatement pstmt = con.prepareStatement("insert into myTable values (?, ?, ?)");
pstmt.setRowId(1, rowId);
pstmt.setString(2, "Raja");
pstmt.setString(3, "Hyderabad");

