title: How to get all resultset values from a MySQL database?
body: <p>I need to select multiple columns from a table which have multiple result set value. I found some question already been answered, but couldn't find a specific one that would help me in my condition. </p>
  
  <p>I tried this but still no luck:</p>
  
  <pre><code>String dboutp = "";
  try {
      DBConnect Database = new DBConnect();
      Connection con = Database.getcon();
      String query="SELECT ITEM, PHP FROM table WHERE name=?";
      PreparedStatement ps = con.prepareStatement(query);
      ps.setString(1, name);
      ResultSet rs=ps.executeQuery();
      int columnCount = 0;
      Object[] row = new Object[columnCount];
      for (int i = 1; i &lt;= columnCount; ++i) {
          row[i - 1] = rs.getString(i); // Or even rs.getObject()
          System.out.println(row[i-1]);
      }
      DefaultTableModel model = null;
      model.addRow(row);
      con.close();
  } catch (SQLException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>I also tried:</p>
  
  <pre><code>String dboutp = "";
  try {
      DBConnect Database = new DBConnect();
      Connection con = Database.getcon();
      String query="SELECT ITEM, PHP FROM table WHERE name=?";
      PreparedStatement ps = con.prepareStatement(query);
      ps.setString(1, name);
      ResultSet rs=ps.executeQuery();
      int i=1;
      while(rs.next()){
          dboutp=dboutp+","+rs.getString(i);
          i++;
      }
      con.close();
  } catch (SQLException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>At first method in line <code>model.addRow(row)</code> I'm getting an exception saying <code>java.lang.NullPointerException</code>, and in second method this exception occurs: <code>java.sql.SQLException: Column Index out of range, 2 &gt; 1</code>.</p>
  
  <p>I would really appreciate if someone tell me what is the appropriate way of accessing multiple result set values including multiple column values.</p>