More Related Content
Similar to Scrollable Test App
Similar to Scrollable Test App (20)
Scrollable Test App
- 1. Scrollable Test App
package com.nt.gui;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.Statement;
publicclassScrollableTest{
publicstaticvoidmain(String[] args) throws Exception{
//registerdriverandcreate connection
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","password");
//create Statementobj withtype mode andvalues
Statementst=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
//create ResultSetobj
ResultSetrs=st.executeQuery("select*fromstudent");
//displayingresulttop-bottom
System.out.println("Top--BottomResult");
while(rs.next()){
System.out.println(rs.getInt(1)+""+rs.getString(2)+""+rs.getInt(3)+""+rs.getInt(4)+"
"+rs.getInt(5)+""+rs.getString(6));
}
//displayingresultbottom--top
System.out.println("Bottom--TopResult");
rs.afterLast();
- 2. while(rs.previous()){
System.out.println(rs.getInt(1)+""+rs.getString(2)+""+rs.getInt(3)+""+rs.getInt(4)+"
"+rs.getInt(5)+""+rs.getString(6));
}
//displayingrecordsrandomly
System.out.println("displaying randomrecords...");
rs.first();//settingresultsetatfirstrowit will give firstrow
System.out.println(rs.getRow()+"---->"+rs.getInt(1)+""+rs.getString(2)+""+rs.getInt(3)+"
"+rs.getInt(4)+""+rs.getInt(5)+""+rs.getString(6));
rs.last();//giveslastrecord
System.out.println(rs.getRow()+"---->"+rs.getInt(1)+""+rs.getString(2)+""+rs.getInt(3)+"
"+rs.getInt(4)+""+rs.getInt(5)+""+rs.getString(6));
rs.relative(-2);//givesrecordrelative tocurrentpointingrow
System.out.println(rs.getRow()+"---->"+rs.getInt(1)+""+rs.getString(2)+""+rs.getInt(3)+"
"+rs.getInt(4)+""+rs.getInt(5)+""+rs.getString(6));
rs.absolute(4);//gives4throwrecord
System.out.println(rs.getRow()+"---->"+rs.getInt(1)+""+rs.getString(2)+""+rs.getInt(3)+"
"+rs.getInt(4)+""+rs.getInt(5)+""+rs.getString(6));
rs.absolute(-2);//givessecondlastrecord..here
System.out.println(rs.getRow()+"---->"+rs.getInt(1)+""+rs.getString(2)+""+rs.getInt(3)+"
"+rs.getInt(4)+""+rs.getInt(5)+""+rs.getString(6));
rs.relative(1);//giveslastrecord
System.out.println(rs.getRow()+"---->"+rs.getInt(1)+""+rs.getString(2)+""+rs.getInt(3)+"
"+rs.getInt(4)+""+rs.getInt(5)+""+rs.getString(6));
//close jdbcobjs