hi pple
I am practicing on this java gui interface, where it will hve to go from the first, next previous or last record. right now I am working on the next button but run into an runtime error.can some tell me what to do and how to fix it.
here is the codes, where in the codes did i went wary
public class jtab extends javax.swing.JFrame {
Connection conn;
ResultSet rs;
Statement stmt;
public jtab() {
initComponents();
DoConnect();
}
public void DoConnect(){
try{
//connect to the database
String host ="jdbc:JTab://localhost:3306/lecturer";
String uName = "admin";
String uPass ="admin";
//execute some sql and load the record into the result set
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "SELECT * FROM jtab";
rs = stmt.executeQuery(sql);
//move the cursor the first record and get the data
rs.next();
int studentID = rs.getInt("studentID");
String ID = Integer.toString(studentID);
String date = rs.getString("date");
String coursecrn = rs.getString("course_crn");
String coursecode = rs.getString("course_code");
String subject = rs.getString("subject");
//display the first record in the field
txtfieldstudentID.setText(ID);
txtfieldDate.setText(date);
txtfieldcourse_crn.setText(coursecrn);
txtfieldcourse_code.setText(coursecode);
txtfieldsubject.setText(subject);
}
catch(SQLException err){
JOptionPane.showMessageDialog(jtab.this, err.getMessage());
}
}
this is the codes ah used for the next button
private void btnnextActionPerformed(java.awt.event.ActionEvent evt) {
try{
if(rs.next()){
}
else{
rs.previous();
JOptionPane.showMessageDialog(jtab.this,"End of File");
}
}catch(SQLException err){
JOptionPane.showMessageDialog(jtab.this,err.getMessage());
}
try{
if(rs.next()){
int studentID = rs.getInt("studentID");
String ID = Integer.toString(studentID);
String date = rs.getString("Date");
String coursecrn = rs.getString("coursecrn");
String coursecode = rs.getString("coursecode");
String subject = rs.getString("subject");
txtfieldstudentID.setText(ID);
txtfieldDate.setText(date);
txtfieldcourse_crn.setText(coursecrn);
txtfieldcourse_code.setText(coursecode);
txtfieldsubject.setText(subject);
}
else{
rs.previous();
JOptionPane.showMessageDialog(jtab.this, "End of File");
}
}
catch(SQLException err){
JOptionPane.showMessageDialog(jtab.this, err.getMessage());
}
}

