title: Java - How to fetch all rows data from database
body: <p>i'm making simple lab management system using java swing GUI where i need to print out all patients data from database table but i cannot found how to retrieve all rows data from database. With below code i'm getting only last row data.</p>
  
  <pre><code>private void inner_search_btnActionPerformed(java.awt.event.ActionEvent evt) {                                                 
      String search = this.search_field.getText();
      String name = null;
      try{
          if(search.trim().length() == 0){
              this.results_field.setText("Please fill in search field !!!");
          }
          else
          {
              String query = "select * from lab_tests";
              rs = st.executeQuery(query);
  
  
  
              int i =0;
  
              while(rs.next())
              {                   
                  i++;
                  name = rs.getString("patient_name");                
                  this.results_field.setText("&lt;html&gt;" + name + "&lt;br&gt;&lt;/html&gt;");
              }
  
          }
      }
      catch(Exception ex){
  
      }
  }   
  </code></pre>