It is a connected Rowset. It is an interface and implemented by JDBC driver developer.
void setUrl(String url) - Sets the URL this rowset object will use when it uses the DriverManager to create a connection.
void setUsername(String username) - Sets the username property for this Rowset object to the given string.
void setPassword(String password) - Sets the database password for this Rowset object to the given string.
void setCommand(String query) - Sets this Rowset objects command property to the given SQL query.
void execute() - Fills this Rowset object with data.
Note : JdbcRowSet is an interface and OracleJdbcRowSet is a class
PROGRAM TO FETCH RECORD USING JDBCROWSET
import java.sql.*;
import oracle.jdbc.rowset.OracleJDBCRowSet;
public class Test36 {
public static void main(String[] args)throws Exception {
OracleJDBCRowSet ojds = new OracleJDBCRowSet();
ojds.setUrl("jdbc:oracle:thin:@localhost:1521:orcl");
ojds.setUsername("scott");
ojds.setPassword("rakesh");
ojds.setCommand("select empno,ename,sal from emp");
ojds.execute();
while(ojds.next())
{
System.out.println(ojds.getInt(1)+" "+ojds.getString(2)+" "+ojds.getFloat(3));
}
}
}
Output -
7369 SMITH 1600.0
7499 ALLEN 2100.0
7521 WARD 1750.0
7566 JONES 3675.0
7654 MARTIN 1750.0
7698 BLAKE 3350.0
7782 CLARK 2950.0
7788 SCOTT 3700.0
7839 KING 5500.0
7844 TURNER 2000.0
7876 ADAMS 1800.0
7900 JAMES 1450.0
7902 FORD 3700.0
7934 MILLER 1800.0
No comments:
Post a Comment