It's not a secret anymore!*
The moose likes JDBC 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "A question on Result Set Forward Only  " Watch "A question on Result Set Forward Only  " New topic
Author

A question on Result Set Forward Only

Johnson David
Greenhorn

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
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.
Wei Dai
Ranch Hand

Joined: Jun 22, 2005
Posts: 86
>stmt=con.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
> while(rs.previous())
Maybe it's a bug of mysql jdbc driver.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: A question on Result Set Forward Only
 
Similar Threads
How can I get the previous record in Oracle?
Result set type is TYPE_FORWARD_ONLY
resultset
ResultSet TYPE
updatable recordsets in SYBASE