title: How to retrieve all the name from MySQL?
body: <p>I want to retrieve all the name and the number of row from MySQL to java. So far I only able to retrieve the total row number but I only get the last name. What's wrong here ?</p>
  
  <p><strong>StaffManagement.java</strong></p>
  
  <pre><code>adminAPI api= new adminAPI();
  try {
        int num= api.displayCheckBoxAndLabel();
        String allName= api.displayName();
        System.out.println(num+allName);
  }
  </code></pre>
  
  <p><strong>adminAPI</strong></p>
  
  <pre><code>public int displayCheckBoxAndLabel() throws Exception // get the number of row 
      {
          int count = 0;
          String sql="Select count(*) AS adminID from admin";
          DatabaseConnection db = new DatabaseConnection();
          Connection  conn =db.getConnection();
          PreparedStatement  ps = conn.prepareStatement(sql);
           ResultSet rs = ps.executeQuery();
           while(rs.next()) 
           {  
               count= rs.getInt("adminID");
  
           }
           ps.close();
           rs.close();
           conn.close();
           return count ;
      }
  
      public String displayName() throws Exception // get all the name 
      {
          String name = null;
          String sql="Select name from admin";
          DatabaseConnection db = new DatabaseConnection();
          Connection  conn =db.getConnection();
          PreparedStatement  ps = conn.prepareStatement(sql);
           ResultSet rs = ps.executeQuery();
           while(rs.next()) 
           {  
               name= rs.getString("name");
  
           }
           ps.close();
           rs.close();
           conn.close();
           return name ;
      }
  </code></pre>