@Override public List<ProductProject1Bean> selectAll(String prod_name) { // List<ProductProject1Bean> result = null; try ( // Connection conn = DriverManager.getConnection(URL, USERNAME, // PASSWORD); Connection conn = dataSource.getConnection(); ) { PreparedStatement stmt = conn.prepareStatement(SELECT_All_BY_PROD_NAME); stmt.setString(1, prod_name); ResultSet rset = stmt.executeQuery(); result = new ArrayList<ProductProject1Bean>(); while (rset.next()) { ProductProject1Bean bean = new ProductProject1Bean(); bean.setMem_id(rset.getInt("mem_id")); bean.setProd_name(rset.getString("prod_name")); bean.setSize(rset.getString("size")); bean.setColor(rset.getString("color")); bean.setCount(rset.getInt("count")); bean.setPrice(rset.getInt("price")); bean.setBrand(rset.getString("brand")); bean.setGender(rset.getString("gender")); bean.setPart(rset.getString("part")); bean.setLaunch_date(rset.getDate("launch_date")); bean.setNote(rset.getString("note")); result.add(bean); } } catch (SQLException e) { e.printStackTrace(); } return result; }
// private StringBuilder orderbydate = new StringBuilder("order by launch_date"); // private StringBuilder orderbyprice = new StringBuilder("order by price"); // private StringBuilder select = new StringBuilder("select * from product where prod_name =? "); // private StringBuilder selectall = new StringBuilder("select * from product where prod_name like // '%'+?+'%' "); // private static final String SELECT_BY_PROD_NAME = "select * from product where prod_name =?"; @Override public List<ProductProject1Bean> select(String prod_name, String SQLprice, String SQLorder) { // List<ProductProject1Bean> result = null; try ( // Connection conn = DriverManager.getConnection(URL, USERNAME,PASSWORD); Connection conn = dataSource.getConnection(); ) { StringBuilder SELECT = new StringBuilder("select * from product where prod_name =?"); SELECT.append(SQLprice); // and price between xxx and xxx SELECT.append(SQLorder); // order by xxx System.out.println("SELECT= " + SELECT.toString()); PreparedStatement stmt = conn.prepareStatement(SELECT.toString()); stmt.setString(1, prod_name); ResultSet rset = stmt.executeQuery(); result = new ArrayList<ProductProject1Bean>(); while (rset.next()) { ProductProject1Bean bean = new ProductProject1Bean(); bean.setMem_id(rset.getInt("mem_id")); bean.setProd_name(rset.getString("prod_name")); bean.setSize(rset.getString("size")); bean.setColor(rset.getString("color")); bean.setCount(rset.getInt("count")); bean.setPrice(rset.getInt("price")); bean.setBrand(rset.getString("brand")); bean.setGender(rset.getString("gender")); bean.setPart(rset.getString("part")); bean.setLaunch_date(rset.getDate("launch_date")); bean.setNote(rset.getString("note")); result.add(bean); } } catch (SQLException e) { e.printStackTrace(); } return result; }