File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Current value for Resultset.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Current value for Resultset.." Watch "Current value for Resultset.." New topic
Author

Current value for Resultset..

Bhardwaj Shweta
Ranch Hand

Joined: Mar 29, 2011
Posts: 36

Hello

i want to navigate thorugh my code in servlets..If i want to code for previous Button,first i need to move my cursor to current record so that user can move to previous record..

but i am not getting how to move to current record.my cursor is set on second record and rs.first() only returns boolean value..
Please tell me some function for rs.currentrecord()...
Thanks

Regards,
Shweta Bhardwaj
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1448
    
    6

It's true that return type of method is boolean. Reason is the method tries to move the record pointer to the first record, if the recrodset has any record it will return true or else false. So after calling rs.first(), if you get true value, you are pointed on the first record. Now if you retrieve column values from here, you will get the values of first record.


Swastik
Bhardwaj Shweta
Ranch Hand

Joined: Mar 29, 2011
Posts: 36

hey swastik thanks for your reply,but what about moving to current record..in case of previous how can i move my cursor to current record.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1448
    
    6

Shweta

I could not get your query very clearly. What exactly do you mean by current record? Once a recordset is created the pointer is typically before the first row. Calling next takes you the next row, calling previous takes you to the previous row. Apart from these you have methods like first,last,relaive,absolute etc. So, what exactly do you mean by current record. Could you please elaborate a more?
Bhardwaj Shweta
Ranch Hand

Joined: Mar 29, 2011
Posts: 36

can you provide me the logic for traversing previous records.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1448
    
    6

What is going wrong with your code?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1448
    
    6

Ok, as much as I understood probably your code is taking you the first record, correct me if I am wrong. But probably you wish to move to the exactly the previous record from the current record, right? Moreover as because it's a servlet application, every time the request goes, the pointer is pointed before the first row, right?
Bhardwaj Shweta
Ranch Hand

Joined: Mar 29, 2011
Posts: 36

Eggjacktly Thats my problem
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1448
    
    6

And as because it's a servlet application, every time the request goes, the pointer is pointed before the first row, right?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

rs.absolute(row). There's also a relative method that moves the cursor forward or backward a number of records. Swastik already mentioned these.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1448
    
    6

That's true Rob, but probably we need to retain the last positioned row in session, correct me if I am wrong?
Bhardwaj Shweta
Ranch Hand

Joined: Mar 29, 2011
Posts: 36

true
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1448
    
    6

And when the next request comes, retrieve the value from session, and call absolute(retrieved value from session-1), right?
Bhardwaj Shweta
Ranch Hand

Joined: Mar 29, 2011
Posts: 36

Thanks guys
let me try this
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Current value for Resultset..
 
Similar Threads
Problem with String
an easy js math question
Strings...
String question
Strings, StringBuffer and equals()