Problems with JDBC ResulltSet

Hi,
i am in trouble of reusing the resultset during runtime.
The following method creates a frame and loads the information about 1st student in textFields from stdinfo table of the database.

public void runAdmin() {
final admin adm=new admin();
String sql="select * from stdinfo";
Statement stm=new DBCon().getDBCon();

try{

ResultSet rs=stm.executeQuery(sql);
if(rs.first()){
rs.first();
adm.txtId.setText(rs.getString("ID"));
adm.txtName.setText(rs.getString("name"));
adm.txtAddress.setText(rs.getString("address"));
adm.txtPhone.setText(rs.getString("phone"));
adm.txtSex.setText(rs.getString("sex"));
adm.txtAge.setText(rs.getString("age"));

// stm.close();

}
}catch(SQLException e){
e.printStackTrace();
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {

adm.setVisible(true);

}
});
}


now I want to use this result set in the following methods so that when "next" or "previous" button is cliked of admin frame it shows accordingly the next or previous student information of the stdinfo table.


private void cmdNextActionPerformed(java.awt.event.ActionEvent evt) {


}
private void cmdPrevActionPerformed(java.awt.event.ActionEvent evt) {



}



How can I solve this problem.Pls help!

Thanks.

Comments

  • Try to instantiate your resultset where it is visible to the other methods from which you want to use it.
    A possibility is instantiating the resultset with global scope for the class


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion