ResultSet interface in java

ResultSet interface

The ResultSet interface is the object which is created & used to get the information for SQL statement
The select statement returns a cursor which is used to navigate through the result
For getting the result set object, we should do the following
 Connect to a database
 Create SQL statement which returns the result from the database
 Write query
 Execute query
Drawback of result set is that there is no previous method

ResultSet interface methods

close()
Closes current ResultSet

getBoolean()
Returns column as boolean value

getByte()
Returns column as array of bytes

getDate()
Returns column as Date object in java

getDouble()
Returns column as double

getFloat()
Returns column as float

getString()
Returns a column as String

next()
Moves pointer to next record

Example
import java.sql.*;
class test
{
public static void main(String args[])throws Exception
{
Class.forName(“oracle.jdbc.driver.OracleDriver”);
Connection con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:xe”,”system”,”system”);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(“select * from tab”);
System.out.println(rs.getString(1)+” “+rs.getString(2)+” “+rs.getString(3));
con.close();
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *