Tuesday, 5 February 2013

SCROLLABLE RESULTSET | Java J2EE Tutorial pdf

SCROLLABLE RESULTSET

So far we ‘ve been navigating JDBC result sets using the next() method, which enables us to move forward only. Another option is to create a Scrollable result set, so the cursor can navigate the result set both backward and forward. A two-argument version of the createStatement() method exists. The first argument specifies the type of scrolling (TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, TYEP_SCROLL_SENSITIVE), and the second enables us to make the result set either read-only or updateable (CONCUR_READ_ONLY or CONCUR_UPDATABLE, respectively), as in the following example:
import java.sql.*;
public class jdbc_type1_scroll {
public static void main(String a[]) throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:TEST");
Statement st=con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs=st.executeQuery("select * from Emp");
rs.next();
System.out.println(rs.getString(3));
rs.last();
System.out.println(rs.getString(3));
rs.previous();
System.out.println(rs.getString(3));
rs.absolute(3);
System.out.println(rs.getString(3));
rs.first();
rs.close();
st.close();
con.close();
}
}
Table
ename            eage        ecity             esalary                   epin
---------- ----------- ---------- --------------          -------- -----------
shimith          23          banglore        9000.0                   3222
emp5            30          pune             2345.0                    1221
ved               30          allahabad      2345.0                    12345
bill                 30         texsas           2345.0                     4321
Output

No comments: