title: java.sql.SQLException: The column position '1' is out of range
body: <p>I have this error and I do not understand it, can someone tell me what I am doing wrong?</p>
  
  <p>java.sql.SQLException: The column position '1' is out of range.  The number of columns for this ResultSet is '0'.</p>
  
  <pre><code>public Object[][] searchFunction(String searchWord, String loginId) {
      Object[][] data = new Object[5][6];
      String[] tableName = {"subject", "sender", "recipient", "label", "message"};
      int nr = 0, i = 0, q = 1;
      boolean hasRows = false;
      for(int j = 0; j&lt;5; j++) {
          try {    
              PreparedStatement prepareStatement = con.prepareStatement("SELECT * FROM messages WHERE sender = ? AND " + tableName[j] + " LIKE '%Done%' ORDER BY id ASC");    
              prepareStatement.setString(1, loginId);     
              rs = prepareStatement.executeQuery();
              while (rs.next()) {
                  hasRows = true;
                  boolean check = true;
                  int id = rs.getInt("id");
                  int priority = rs.getInt("priority");
                  String recipient = rs.getString("recipient");
                  String labelDb = rs.getString("label");
                  String subject = rs.getString("subject");    
                  String date = rs.getString("date");    
                  String stars = setPriorityStars(priority);
  
                  for(int k=0; k&lt;i+1; k++) {
                      Object idObj = (Integer) id;
                      if(data[k][0] == idObj) check = false; 
                  }
  
                  if(check == true) {
                          data[i][0] = q;
                          data[i][1] = stars;
                          data[i][2] = recipient;
                          data[i][3] = labelDb;
                          data[i][4] = subject;
                          data[i][5] = date;
                          i++;
                          nr++;
                          q++;
                      }
  
              }
              if(hasRows == false) {
              data = getInbox(loginId);
              JOptionPane.showMessageDialog(null, "There is no fields that includes " + searchWord);
              break;
              }
          } catch(Exception ex) {
              System.out.println(ex);
          }
      }
      System.out.println("Found " + nr + " results");
      return data;
  }
  </code></pre>