Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to make a ResultSet scrollable

 
Gayani Kanchana
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im writing a java web application using net beans 5.5 and SQL server. I want to read same result set twice. therefore i use resultSet.first(). to go to the first record in record set. How ever it throws an exception.
how can I move to first record after i reached end of record set.

Please help.
thanks
 
krishnamoorthy kitcha
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gayani Kanchana ,

First of all you had retrieved all the datas from the result set like

ResultSet rs=ps.executeQuery(sql);
int i=0;
while (rs.next()){
String a =rs.getColumn(i);

}


then

you will try like this

if(rs.last())
{
rs.beforeFirst();

while(rs.next()){

same code
}

}


check and tell me your feedback

Regards,
k.krishnamoorthy.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15359
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the API documentation of class java.sql.Connection. There are variants of the methods createStatement(), prepareStatement() and prepareCall() that allow you to specify the result set type. There, you can specify that you need a scrollable result set.

Also, your JDBC driver needs to support scrollable result sets, otherwise it isn't going to work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic