public ArrayList<RefSupplier> MonitorRefSupplier() { ArrayList<RefSupplier> refSupplier = new ArrayList<RefSupplier>(); try { DBConnectionFactory myFactory = DBConnectionFactory.getInstance(); Connection conn = myFactory.getConnection(); PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM `ref_supplier`"); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { RefSupplier newRefSupplier = new RefSupplier(); newRefSupplier.setSupplierID(rs.getInt("supplierID")); newRefSupplier.setItemCode(rs.getInt("itemCode")); newRefSupplier.setItemName(rs.getString("itemName")); newRefSupplier.setCompanyName(rs.getString("companyName")); newRefSupplier.setCompanyAddress(rs.getString("companyAddress")); newRefSupplier.setContactPerson(rs.getString("contactPerson")); newRefSupplier.setContactNumber(rs.getInt("contactNumber")); refSupplier.add(newRefSupplier); System.out.println(refSupplier.get(0).getCompanyName()); } pstmt.close(); rs.close(); conn.close(); return refSupplier; } catch (SQLException ex) { Logger.getLogger(RefSupplierDAO.class.getName()).log(Level.SEVERE, null, ex); } return null; }
public ArrayList<RefSupplier> searchSupplier(String itemName) throws SQLException { DBConnectionFactory myFactory = DBConnectionFactory.getInstance(); Connection conn = myFactory.getConnection(); String query = "SELECT * FROM `ref_supplier` WHERE itemName LIKE '%" + itemName + "%'"; PreparedStatement ps = conn.prepareStatement(query); ArrayList<RefSupplier> RefSupplierList = new ArrayList(); ResultSet rs = ps.executeQuery(); while (rs.next()) { RefSupplier RefSupplierN = new RefSupplier(); RefSupplierN.setSupplierID(rs.getInt("supplierID")); RefSupplierN.setItemCode(rs.getInt("itemCode")); RefSupplierN.setItemName(rs.getString("itemName")); RefSupplierN.setCompanyName(rs.getString("companyName")); RefSupplierN.setCompanyAddress(rs.getString("companyAddress")); RefSupplierN.setContactPerson(rs.getString("contactPerson")); RefSupplierN.setContactNumber(rs.getInt("contactNumber")); RefSupplierList.add(RefSupplierN); } rs.close(); return RefSupplierList; }