Reputation: 321
Hi I am new to JDBC concept and as per my knowledge to move the resultset pointer in both direction resultset needs to be set scrollable
But since the resultset is not set to scrollable absolute function should not allow the pointer to move back
but the below code is working fine
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from studentinfo");
int counter=0;
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2));
int row = rs.getRow();
if(row==5)
{
if(counter==0)
{
counter++;
rs.absolute(4);
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
}
}
con.close();
In this code, I am moving the pointer back to the 4th row if the current row is equal to 5th
and as you can see I haven't given any parameter in createStatement() method i.e. by default it should be ** nonscrollable** and hence above code should not fetch results however its working fine how so?
Upvotes: 0
Views: 744
Reputation: 246788
The JDBC specification says:
The default
ResultSet
type isTYPE_FORWARD_ONLY
.The method
DatabaseMetaData.supportsResultSetType
returnstrue
if the specified type is supported by the driver andfalse
otherwise.If the driver does not support the type supplied to the methods
createStatement
,prepareStatement
, orprepareCall
, it generates anSQLWarning
on theConnection
object that is creating the statement. When the statement is executed, the driver returns aResultSet
object of a type that most closely matches the requested type. An application can find out the type of aResultSet
object by calling the methodResultSet.getType
.
Check if TYPE FORWARD_ONLY
is supported by your JDBC driver.
Check if you get an SQLWarning
.
Check what ResultSet
type you got.
Upvotes: 2