제품이 MySQL 데이터베이스에 남아 있어 역시 맵(Map)으로 저장하는 메서드가 필요하다.
public static Map<Integer, String> loadItems() { Map<Integer, String> products = new HashMap<Integer, String>(); try { Connection con = DriverManager.getConnection(“jdbc:mysql://localhost/apriori”,“root”,””); PreparedStatement pstmt = con.prepareStatement(“SELECT * FROM products”); ResultSet rs = pstmt.executeQuery(); while(rs.next()) { products.put(new Integer(rs.getInt(“id”)), rs.getString(“productname”)); } rs.close(); pstmt.close(); con.close(); } catch(Exception e) { e.printStackTrace(); } return products; }