How to retrieve previous query using Swing JButton
I wrote a code sometime ago in which the object of ResultSet
class res was able to retreive the nex开发者_如何学运维t row of the database by using res.next()
. But when res.previous()
was used it was not working even though the method is defined in the resultset class.
public void actionPerformed(ActionEvent e) {
if (e.getSource() == next) {
try {
res.next();
} catch(Exception ee) {
}
showRecord(res);
}
}
Here res.next()
was fine but res.previous()
was not working even though it never gave any error or warning. It never worked even though I made it TYPE INSENSITIVE
?
showRecord(res);
is used for printing the row.
This is a bad idea. You shouldn't be passing ResultSet instances around. I'd recommend mapping it into an object or data structure, closing all the JDBC resources in a finally block, and passing the object or data structure back to the UI layer.
If you insist on ResultSet, all the other comments above still apply. Just use a CachedRowSet instead of ResultSet.
You can navigate that data structure or object any way you like then, because you're not tethered to the database anymore. You'll just have to be smart about how much data you bring back at a time. You'll also need a strategy for going back and getting the next chunk if you need it.
精彩评论