File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes A question on Result Set Forward Only  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "A question on Result Set Forward Only  " Watch "A question on Result Set Forward Only  " New topic

A question on Result Set Forward Only

Johnson David

Joined: May 22, 2005
Posts: 27
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

Joined: Jun 22, 2005
Posts: 86
> while(rs.previous())
Maybe it's a bug of mysql jdbc driver.
I agree. Here's the link:
subject: A question on Result Set Forward Only
It's not a secret anymore!