title: adding data to hashmap from database
body: <p>Hello I am creating an application where I can store data in a Hashmap and List for a shopping cart module.But I want to fetch this data from my MS-Access database.I tried the following code but its not compiling.Please give me guidance.</p>
  
  <p>Code:</p>
  
  <pre><code>import java.sql.*;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  
  public class Program {
      public static void main(String [] args){}
  
      public static HashMap getProductsAsMap() {
          try {
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection con = DriverManager.getConnection("jdbc:odbc:pd");
              ResultSet rs = null;
              Statement st = con.createStatement();
              String sql = ("select * from products");
              rs=st.executeQuery(sql);
              while (rs.next()) { 
                  HashMap&lt;String, ProductBean&gt; products= new HashMap&lt;String, ProductBean&gt;();
                  String name=rs.getString("pname");
                  String desc=rs.getString("pdesc");
                  String image=rs.getString("pimage");
                  products.put("P1", new ProductBean(name,desc,image));
                  return products;
              }
              rs.close();
              st.close();
              con.close();
          }
          catch(Exception e){}   
      }
  
      public static List getProductsAsList() {
          List&lt;ProductBean&gt; products = new ArrayList&lt;ProductBean&gt;();
          try {
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection con = DriverManager.getConnection("jdbc:odbc:pd");
              ResultSet rs = null;
              Statement st = con.createStatement();
              String sql = ("select * from products");
              rs=st.executeQuery(sql);
              while (rs.next()) { 
                  String name=rs.getString("pname");
                  String desc=rs.getString("pdesc");
                  String image=rs.getString("pimage");
                  products.add(new ProductBean(name,desc,image));
              }
              rs.close();
              st.close();
              con.close();
          }
          catch(Exception e){}
          return products;  
      }
  }
  </code></pre>
  
  <p>I get 2 errors as follows:</p>
  
  <p><img src="https://i.stack.imgur.com/k0BFo.jpg" alt="enter image description here"></p>