Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading from a database to a jlist brings errors
    primarykey
    data
    text
    <p>I have created a database and every entry from the JList will be added to a table in the database. This work perfectly, but my next task is to get whatever is in the database to load to the JList. I have a function created within the button but it brings up errors. I'm struggling with how to fix this so I hope somebody can resolve it.</p> <p>Thanks</p> <p>Here is my code:</p> <pre><code>JButton btnDb1 = new JButton("J"); btnDb1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { ResultSet rs = st.executeQuery("SELECT * FROM patient"); while (rs.next()) { Patient patient = new Patient(patientname, patientaddress, patientphone, patientid); patient.setName(rs.getString("patientname")); patient.setAddress(rs.getString("patientaddress")); patient.setPhoneNum(rs.getString("patientphone")); patient.setID(rs.getInt("patientid")); MainDentist.model.addElement(patient); } } catch (Exception e) { System.out.println(" Error "); } } }); btnDb1.setBounds(200, 393, 120, 23); contentPane.add(btnDb1); </code></pre> <p>Here is my patient class:</p> <pre><code>public class Patient { public String patientName; public String patientAddress; public String patientPhone; public int patientID; public Patient(String patientname, String patientaddress, String patientphone,int patientid){ patientName = patientname; patientAddress = patientaddress; patientPhone = patientphone; patientID = patientid; } public String setName(String patientname){ return patientName = patientname; } public String getName(){ return patientName; } public String setAddress(String patientaddress){ return patientAddress = patientaddress; } public String getAddress(){ return patientAddress; } public String setPhoneNum(String patientphone){ return patientPhone = patientphone; } public String getPhoneNum(){ return patientPhone; } public int setID(int patientid){ return patientID = patientid; } public int getID(){ return patientID; } public String toString() { // Printing the patient's details to the scroll pane return "Patient Name: " + patientName + ", PatientAddress: " + patientAddress + ", PatientPhone: " + patientPhone + ", patientID: " + patientID +"" ; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload