使用 Java 从 oracle 获取行 ID
fetch row id from oracle using Java
我需要使用 Java 从 Oracle 数据库中获取 rowid。我使用了下面的代码。
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("select * from ABC");
while(rs.next()) {
RowId str=rs.getRowId(1);
System.out.println(str);
}
我得到的结果是
oracle.sql.ROWID@2ce6c6ec
oracle.sql.ROWID@1bae316d
但我需要像
这样的十六进制值
AAAdItACwAABXcIAAA
有人可以指导我吗?
谢谢
来自 Java 文档
Retrieving RowId Objects Retrieve a java.sql.RowId object by calling
the getter methods defined in the interfaces ResultSet and
CallableStatement. The RowId object that is returned is an immutable
object that you can use for subsequent referrals as a unique
identifier to a row. The following is an example of calling the
ResultSet.getRowId method:
java.sql.RowId rowId_1 = rs.getRowId(1);
字符串到字符串()
Returns 表示此 java.sql.RowId 对象指定的 SQL ROWID 值的字符串。
这将直接为您提供十六进制值
String hexValue = DatatypeConverter.printHexBinary(resultSet.getRowId(10).getBytes())
这是完整的代码
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("select * from ABC");
while(rs.next())
{
String str= DatatypeConverter.printHexBinary(resultSet.getRowId(1).getBytes())
System.out.println(str);
}
我需要使用 Java 从 Oracle 数据库中获取 rowid。我使用了下面的代码。
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("select * from ABC");
while(rs.next()) {
RowId str=rs.getRowId(1);
System.out.println(str);
}
我得到的结果是
oracle.sql.ROWID@2ce6c6ec
oracle.sql.ROWID@1bae316d
但我需要像
这样的十六进制值AAAdItACwAABXcIAAA
有人可以指导我吗?
谢谢
来自 Java 文档
Retrieving RowId Objects Retrieve a java.sql.RowId object by calling the getter methods defined in the interfaces ResultSet and CallableStatement. The RowId object that is returned is an immutable object that you can use for subsequent referrals as a unique identifier to a row. The following is an example of calling the ResultSet.getRowId method:
java.sql.RowId rowId_1 = rs.getRowId(1);
字符串到字符串() Returns 表示此 java.sql.RowId 对象指定的 SQL ROWID 值的字符串。
这将直接为您提供十六进制值
String hexValue = DatatypeConverter.printHexBinary(resultSet.getRowId(10).getBytes())
这是完整的代码
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("select * from ABC");
while(rs.next())
{
String str= DatatypeConverter.printHexBinary(resultSet.getRowId(1).getBytes())
System.out.println(str);
}