JDBC ReusultSet Type

S

Showmethecode

I was exploring the resultset type in JDBC 2.0 & 3.0 API.
i wrote a very simple n basic code snippet which is as follows:

" Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("Select * from mytest");
int i = rs.getType();
if(i == ResultSet.TYPE_FORWARD_ONLY)
System.out.println("Forward Type Only");

if(i == ResultSet.TYPE_SCROLL_INSENSITIVE)
System.out.println("Scroll Insesitive");

if(i == ResultSet.TYPE_SCROLL_SENSITIVE)
System.out.println("Scroll Sensitive");

rs.absolute(3);
System.out.println("The Id is :" + rs.getInt(1));
System.out.println("The Name is :" + rs.getString(2));

rs.relative(-2);
System.out.println("The Id is :" + rs.getInt(1));
System.out.println("The Name is :" + rs.getString(2));"

After executing this snippet(within a class with main method and
neccessary classes loaded), i m able to pull up data and i saw that
the result type shown is "Forward Type Only" but still when i do
"rs.relative(-2);" it allows me to go back and print the correct
record ( i had 3 records in the table, so this statement prints the
first record).

How is this possible?
is FORWARD_ONLY type is not forward only in strict sense?
what exactly it means by Forward only?

TIA

~showmethecode
 
J

John C. Bollinger

Showmethecode said:
I was exploring the resultset type in JDBC 2.0 & 3.0 API.
i wrote a very simple n basic code snippet which is as follows:

" Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("Select * from mytest");
int i = rs.getType();
if(i == ResultSet.TYPE_FORWARD_ONLY)
System.out.println("Forward Type Only");

if(i == ResultSet.TYPE_SCROLL_INSENSITIVE)
System.out.println("Scroll Insesitive");

if(i == ResultSet.TYPE_SCROLL_SENSITIVE)
System.out.println("Scroll Sensitive");

rs.absolute(3);
System.out.println("The Id is :" + rs.getInt(1));
System.out.println("The Name is :" + rs.getString(2));

rs.relative(-2);
System.out.println("The Id is :" + rs.getInt(1));
System.out.println("The Name is :" + rs.getString(2));"

After executing this snippet(within a class with main method and
neccessary classes loaded), i m able to pull up data and i saw that
the result type shown is "Forward Type Only" but still when i do
"rs.relative(-2);" it allows me to go back and print the correct
record ( i had 3 records in the table, so this statement prints the
first record).

How is this possible?
is FORWARD_ONLY type is not forward only in strict sense?
what exactly it means by Forward only?

Your JDBC driver is buggy. The API spec requires that
ResultSet.absolute() and ResultSet.relative() both throw SQLException
when invoked on a ResultSet instance of type
ResultSet.TYPE_FORWARD_ONLY. It does seem a rather harmless bug, however.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top