• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A question on Result Set Forward Only

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
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.
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>stmt=con.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
> while(rs.previous())
Maybe it's a bug of mysql jdbc driver.
reply
    Bookmark Topic Watch Topic
  • New Topic