In java if we want to navigate the resultset which we get from executing the query using 2 buttons forward and backward. What is the way we can perform this task
private void nextActionPerformed(java.awt.event.ActionEvent evt) {
if(evt.getSource()==bt_previous){
DBUtil util = new DBUtil();
try {
Connection con = util.getConnection();
PreparedStatement stmt = con.prepareStatement("SELECT * FROM DETAILS where id=?");
ResultSet rs;
String rm = id.getText().trim();
stmt.setLong(1, Long.parseLong(rm));
rs = stmt.executeQuery();
while(rs.next()){
String a = rs.getString("weight");
txtboxwgt.setText(a);
String b = rs.getString("note_state");
cbnotstat.setSelectedItem(b);
String c = rs.getString("dm_state");
cbdmnstat.setSelectedItem(c);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
}
Make an entity class
Detail:In your
nextActionPerformedmethod when you iterate over the result set, create a new instance of your entity and add it to some collection, i.e.LinkedList:Then you can navigate the
allDetailsin any manner supported by theLinkedList. Or consider using another collection if LinkedList doesn’t fit your needs.