title: How to fetch a row from database and display it in GUI Eclipse?
body: <p>I am facing a problem while completing my project.</p>
  
  <p>I have created a <code>JFrame</code> with 2 <code>JPanels</code>. The first panel is the login panel, after the user enters his ID and password, he will be directed to the second panel to view his information (ID, Name, Medical Situation) which are saved in the databased connected to my Eclipse project. </p>
  
  <p>The "Login" button already has a query using <code>actionPerformed</code> to verify if the password and ID are correct (if they exist in the database), so the user can login successfully. </p>
  
  <p>What I want to do now is to <strong>create another query</strong>, to fetch (<code>getText</code>) ID, Name and Medical Situation from the database, depending on the ID the user will enter in JTextField = <code>idTXT</code> when he login, and <code>setText</code> in these <code>JLabels</code>: <code>IDdraw_LBL</code>, <code>namedraw_LBL</code>, <code>msdraw_LBL</code> in the second <code>JPanel</code> </p>
  
  <p>Please check my code below:</p>
  
  <pre><code>        btnLogIn.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              try{
                  //setting visibility of panels
                  patient_frame.setVisible(true);
                  patient_login.setVisible(false);
                  patient_appointments.setVisible(false);
  
  
                  //connecting to database
                  Class.forName("com.mysql.jdbc.Driver");
                  Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/clinic", "root", "newpass"); 
  
                  //verifying ID and password code   
                  String query="select * from patients where P_ID=? and Password=?";   
                  PreparedStatement pst=con.prepareStatement(query);
  
                  pst.setString(1, idTXT.getText());
                  pst.setString(2, passwordField.getText());
  
                  ResultSet rs=pst.executeQuery();
                  int count =0;
                  while(rs.next()){
                      count=count+1;
                  }
                  if (count ==1){
  
                      JOptionPane.showMessageDialog(null, "Welcome!");
  
                  }
  
                  else{
                      JOptionPane.showMessageDialog(null, "Incorrect username or password.");
                  }
  
                  rs.close();
                  pst.close();
  </code></pre>
  
  <p>I tried to write another query to retrieve the information from database but it doesn't work:</p>
  
  <pre><code>                idTXT.getText();
  
                  String query1="select * from patients where P_ID=?";
                  PreparedStatement pst1=con.prepareStatement(query1);
                  ResultSet rs1=pst1.executeQuery();
  
                  while (rs1.next()){
  
                      IDdraw_LBL.setText(rs.getString("P_ID"));
                      namedraw_LBL.setText(rs.getString("Name"));
                      msdraw_LBL.setText(rs.getString("Medical_Situation"));
  
                  }
  
                  pst1.close();
  
              }catch(Exception exx) {
                  JOptionPane.showMessageDialog(null, e);
              }
  
          }
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/WWudL.png" rel="nofollow noreferrer">It gives me this long-window error when running the program</a></p>
  
  <p>Any help will be appreciated, Thanks in advance!</p>