- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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");