Hi All
I have read an article that says , Specifying the constant
TYPE_FORWARD_ONLY creates a nonscrollable result set, that
is, one in which the cursor moves only forward. If you do not
specify any constants for the type and updatability, you will
automatically get the default, which is a ResultSet object that is
TYPE_FORWARD_ONLY and CONCUR_READ_ONLY
In my program i have'nt specified any constants , it
means i have created nonscrollable result set, which moves the
cursor in the forward direction only, but in my program i can able to
move the cursor in the backword direction also using previous()
method . can anybody tell me why ,.. here is the code
import java.sql.*;
public class ResultSetTypeDemo
{
public static void main(
String ar[])
{
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/d
ataserver","root","password");Statement stmt=con.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select * from mytable2");
System.out.println(rs.getType());
//it prints 1003 ie type forward only
//but previous() method in the next step should not
// work , but it is working ,
rs.afterLast();
while(rs.previous())
{
String str=rs.getString("name");
int age=rs.getInt("age");
System.out.println(str + " " +age);
}
con.close();
stmt.close();
}catch(ClassNotFoundException e)
{
System.out.println( e.getMessage() );
}
catch(SQLException e1)
{
System.out.println( e1.getMessage());
}
}
}
Here i am using MySql database 4.1 version and jdk 1.5, mysql
driver mysql-connector-java-3.1.10-bin.jar
thax in advance.