How to make the previous buttons and next buttons?
i have a table in the database.
There is a page with three buttons Retrieve, Previous and Next as well as as text fields where the data retrieved does appear.
Once i click on theretrieve button it retrieves a row of information onto the text fields.
I want to be able to move to the previous or next rows on the table and display the information by clicking on the previous or next buttons. At the moment the previous and next buttons does work they throwNullPointerException. only the retrieve button works.
how should i proceed?
below is my code for the three buttons
publicvoid actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals(jbtnRt))
{
try{
rtr ="Select * from Employees";
ResultSet rs = stmt.executeQuery(rtr);
if(rs.next())
{
jFirstName.setText(rs.getString(1));
jSurname.setText(rs.getString(2));
jCity.setText(rs.getString(3));
jCountry.setText(rs.getString(4));
jSSN.setText(rs.getString(5));
}
}
catch(SQLException ce)
{
System.out.println(ce);
}
}
if(ae.getSource().equals(jbtnPrv))
{
try
{
if(rs.previous())
{
jFirstName.setText(rs.getString(1));
jSurname.setText(rs.getString(2));
jCity.setText(rs.getString(3));
jCountry.setText(rs.getString(4));
jSSN.setText(rs.getString(5));
}
else
{
JOptionPane.showMessageDialog(this,"No Records","Database
Error Message", JOptionPane.ERROR_MESSAGE);
rs.first();
}
}
catch(SQLException ce)
{
System.out.println(ce);
}
}
if(ae.getSource().equals(jbtnNt))
{
try
{
if(rs.next())
{
jFirstName.setText(rs.getString(1));
jSurname.setText(rs.getString(2));
jCity.setText(rs.getString(3));
jCountry.setText(rs.getString(4));
jSSN.setText(rs.getString(5));
}
else
{
JOptionPane.showMessageDialog(this,"No Records","Database
Error Message", JOptionPane.ERROR_MESSAGE);
}rs.last();
}
catch(SQLException ce)
{
System.out.println(ce);
}
}
}
any idea how to proceed?

