So what I'm trying to do is when I enter a primary id in a JTextField
and click proceed, it will take that primary id and store it as a new record in another table.
What happens when you click proceed is that it takes you to another app where the primary id is display from the previous app.
My problem here is that it won't let me display the text. My error says:
non-static variable pat_id cannot be referenced from a static context
How do I bypass this?
Here is my code:
private void proceedActionPerformed(java.awt.event.ActionEvent evt) {
try {
String sql = "Insert into medicalRec (patient_id)" + " values (?)";
pst = conn.prepareStatement(sql);
pst.setInt(1, Integer.parseInt(pat_id.getText()));
pst.execute();
new medRec().setVisible(true);
String sql2 = "select * from PATIENT where patient_id=?";
pst = conn.prepareStatement(sql2);
rs = pst.executeQuery();
rs = pst.executeQuery();
if (rs.next()) {
String add0 = rs.getString("patient_id");
medRec.pat_id.setText(add0);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}