When I click my previous button, my textfields are not populated with the values from the DB. It gives me the error of java.sql.SQLException:
Column 'PassengerName' not found.
The column PassengerName
exists in my DB. Can someone tell me what is wrong please?
Here's my code:
public PaymentForm() {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, user, password);
stt = con.prepareStatement("SELECT * FROM payment");
rs = stt.executeQuery();
JOptionPane.showMessageDialog(null, "Connection Successful to Database", "Success", JOptionPane.INFORMATION_MESSAGE);
}catch(Exception e) {
JOptionPane.showMessageDialog(null, "Error in connecting to db", "Error", JOptionPane.ERROR_MESSAGE);
}
initialize();
}
}
JButton btnPrev = new JButton("Previous");
btnPrev.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
if (rs.previous()) {
pass.setSelectedItem(rs.getString("PassengerName"));
int d = rs.getInt("InvoiceNo");
in.setText(String.valueOf(d));
int d2 = rs.getInt("CardNo");
cn.setText(String.valueOf(d2));
double pr = rs.getDouble("Price");
tp.setText(String.valueOf(pr));
nc.setText(rs.getString("Name"));
}else {
rs.next();
JOptionPane.showMessageDialog(null, "No more records");
}
}catch(Exception e1) {
JOptionPane.showMessageDialog(null, "Error");
e1.printStackTrace();