title: How to retrieve data from a database and store in a variable Java?
body: <p>I would like to get data from a database and store in an variable or array. How can I do that? (I'm new on this...)</p>
  
  <pre><code>try{
          String sql = "select * from foodtbl where id ='1'";
          pst = conn.prepareStatement(sql);
          rs = pst.executeQuery();
  
          if(rs.next()){
              food.add(rs.getString(sql));
              rs.close();
              pst.close();
          }
  
      }catch (SQLException ex) {
         // Logger.getLogger(mainmenu.class.getName()).log(Level.SEVERE, null, ex);
      } 
  }          
  </code></pre>