Methods in ResultSet
next()
This method is used to move the cursor to the next row in the result set. It returns a boolean value indicating whether there is a next row or not.while(rs.next()){ // process the current row }
getXxx()
These methods are used to retrieve the values of the columns in the current row. The Xxx represents the data type of the column. For ex. getInt(), getString(), getDate().int id = rs.getInt("id"); String name = rs.getString("name"); Date date = rs.getDate("date");
getObject()
This method is used to retrieve the value of a column in the current row as an Object.Object obj = rs.getObject("column_name");
wasNull()
This method is used to check whether the value of the last column retrieved usinggetXxx()
was null or not.int age = rs.getInt("age"); if(rs.wasNull()){ // age is null }
getMetaData()
This method is used to retrieve the ResultSetMetaData object that contains metadata about the columns in the result set.ResultSetMetaData meta = rs.getMetaData(); int columnCount = meta.getColumnCount(); String columnName = meta.getColumnName(1);
beforeFirst()
This method is used to move the cursor to before the first row in result set.rs.beforeFirst();
absolute()
This method is used to move the cursor to a specific row in the result set.rs.absolute(3);
updateXxx()
These method are used to update the values of the columns in the current row. The Xxx represents the data type of the column For ex. getInt(), getString(), getDate().rs.updateInt("age", 23); rs.updateRow();