viewing records via Jbuttons and resultset
i am trying to view records from a database upon clicking the NEXT buttun in order to bring in the next record. Before that i click SHOW ALL which brings me all the records. However, it only shows me the first and last. I did a system.out.println and it shows me all the records inside the resultset. here is the code for the NEXT button function. I've looked through this code over and over. Let me know what i'm missing.
Any feedback will be great
public void actionPerformed(ActionEvent nextevent)
{
if(nextevent.getActionCommand().equals("Next"))
{
String querynext= "";
try
{
Class.forName(driver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
con= DriverManager.getConnection(url,"app","app");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
querynext= "Select * from CoffeeSuppliers";
results = stmt.executeQuery(querynext);
String nextID;
String nextName;
String nextAddr;
String nextCity;
String nextState;
String nextzip;
String output ="";
while(results.next())
{
nextID= results.getString(1);
nextName= results.getString(2);
nextAddr= results.getString(3);
nextCity = results.getString(4);
nextState= results.getString(5);
nextzip= results.getString(6);
comp_ID.setText(nextID);
comp_Name.setText(nextName);
comp_Addr.setText(nextAddr);
comp_City.setText(nextCity);
comp_State.setText(nextState);
comp_zipcode.setText(nextzip);
output += nextID + " " + nextName + " " + nextAddr + " " + nextCity + " " + nextState + " " + nextzip + "\n";
}// end the while
System.out.println(output);
con.close();
stmt.close();
}
catch(SQLException sqlex)
{
System.err.println("ERROR: " + sqlex.getMessage());
}
}// end the if statement
}
}
if(event.getActionCommand().equals("Show All"))
{
String queryinfo = "Select * FROM CoffeeSuppliers";
try
{
Class.forName(driver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
con= DriverManager.getConnection(url,"app","app");
stmt = con.createStatement();
results = stmt.executeQuery(queryinfo);
while(results.next())
{
String idvalue = results.getString(1);
String NAME = results.getString(2);
String ADDR = results.getString(3);
String CITY = results.getString(4);
String STATE = results.getString(5);
String ZIP = results.getString(6);
comp_ID.setText(idvalue);
comp_Name.setText(NAME);
comp_Addr.setText(ADDR);
comp_City.setText(CITY);
comp_State.setText(STATE);
comp_zipcode.setText(ZIP);
}//end the if statement
con.close();
stmt.close();
}//end try portion of try catch...
catch(SQLException sqlex)
{
System.err.println("ERROR: " + sqlex.getMessage());
}
}
}//end action performed
}//end ShowAllbutton class

