title: How to perform a select query on the ResultSet of another select query in java
body: <p>This is the code where I'm trying to execute a second query on the <code>resultSet</code> of my first lengthy query. I need to upload this 
    data somewhere. </p>
  
  <p>Is it the right thing to do?</p>
  
  <p>Or is there a better approach apart from querying the database again?</p>
  
  <pre><code> public String createQuery() throws SQLException {
       StringBuilder Query = new StringBuilder();
       try {
          Query.append(" SELECT ...... ")
         } catch (Exception e) {
          e.printStackTrace();
      }
      return Query.toString();
  }
   private void openPreparedStatements() throws SQLException {
      myQuery = createQuery();      
      try {
          QueryStatement = dbConnection.prepareStatement(myQuery);
      } catch (SQLException e) {
          e.printStackTrace();
          return;
      }
  }
  public ResultSet selectData(String timestamp) throws SQLException {
      openConnection();
      ResultSet result = null;
      ResultSet rs_new=null;
      try {
          result = QueryStatement.executeQuery();
          while (result.next()) {
             String query = "SELECT * FROM " + result + " WHERE " + "ID" + " =" + "ABC";
              rs_new =QueryStatementNew.executeQuery(query);
              System.out.print(rs_new);
          }
      } catch (SQLException e) {
          LOGGER.info("Exception", e);
      }
  
      return result;
  }
  </code></pre>