AdminImportSourceDAO

 avatar
unknown
plain_text
a year ago
2.7 kB
4
Indexable
public ResultSet GetImportSource() throws ClassNotFoundException {
        ResultSet rs = null;
        try {
            String sql = "Select * From Size";
            PreparedStatement ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
        } catch (SQLException ex) {
            Logger.getLogger(AdminDAOs.class.getName()).log(Level.SEVERE, null, ex);
        }
        return rs;
    }

    public int AddNewImportSource(ImportSource ip) {
        String sql = "insert into Size values(?, ?, ?)";
        int ketqua = 0;
        try {
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setInt(1, ip.getNumSize());
            ps.setInt(2, ip.getProductID());
            ps.setInt(3, ip.getQuantity());
            ketqua = ps.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(AdminDAOs.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ketqua;
    }

    public int UpdateImportSource(ImportSource ip) {
        String sql = "update Size set NumSize=?, ProductID=?, Quantity=? where SizeID=?";
        int ketqua = 0;
        try {
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setInt(1, ip.getNumSize());
            ps.setInt(2, ip.getProductID());
            ps.setInt(3, ip.getQuantity());
            ps.setInt(4, ip.getSizeID());
            ketqua = ps.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(AdminDAOs.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ketqua;
    }

    public int DeleteImportSource(int SizeID) {
        int ketqua = 0;
        try {
            PreparedStatement ps = conn.prepareStatement("delete from Size where SizeID=?");
            ps.setInt(1, SizeID);
            ketqua = ps.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(AdminDAOs.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ketqua;
    }

    public ImportSource GetImportSource(int SizeID) {
        String sql = "Select * From Size where SizeID=?";
        ImportSource ip = null;
        try {
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setInt(1, SizeID);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                ip = new ImportSource(rs.getInt("SizeID"), rs.getInt("NumSize"), rs.getInt("ProductID"), rs.getInt("Quantity"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(AdminDAOs.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ip;
    }