Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

A question on Result Set Forward Only  RSS feed

Johnson David
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

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[])

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");
//it prints 1003 ie type forward only
//but previous() method in the next step should not
// work , but it is working ,

String str=rs.getString("name");
int age=rs.getInt("age");
System.out.println(str + " " +age);
}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.
Wei Dai
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> while(rs.previous())
Maybe it's a bug of mysql jdbc driver.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!