What is RowId object in JDBC Explain?


A RowId is a built-in type of SQL which is an address of a row in a table of a database. The RowId interface of the java.sql package maps with the SQL ROWID value.

RowId values are unique for every row and they are the fastest way to access a row. You cannot use this as a primary key of a table.

Retrieving RowId objects

You can retrieve the RowId of a particular row using the getRowId() method of the ResultSet, CallableStatement, PreparedStatement interfaces.

This method accepts a String value representing a column label or, an integer value representing the column index and returns the respective RowId object.

//Retrieving the RowId objects
RowId rowId1 = rs.getRowId("Mobile_Brand");
RowId rowId2 = rs.getRowId("Unit_Sale");

Setting the RowId values to prepared statement

You can use this as a unique value representing each row. You can set it as a parameter in PreparedStatement using the setRowId() method. To this method, you need to pass an integer representing the parameter index at which you need to set RowId as a value.

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");

Updated on: 30-Jul-2019

375 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements