Untitled

AdminDAOs
mail@pastecode.io avatar
unknown
plain_text
a year ago
2.3 kB
13
Indexable
Never
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package Database;

import Models.Order;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author HP
 */
public class AdminDAOs extends DBConnection{

    public ResultSet GetAllOrder() throws ClassNotFoundException {
        ResultSet rs = null;
        try {
            connect();
            String sql = "Select * From OrderList";
            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 Delete(int id) {
        String sql = "delete from OrderList where ID=?";
        int ketqua = 0;

        try {
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setInt(1, id);
            ketqua = ps.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(AdminDAOs.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ketqua;
    }
      
       public int Update(Order newod) {
        int ketqua = 0;
        String sql = "update Product set pro_name=?, pro_quan=?, pro_price=?, pro_pic=?, pro_des=? where pro_id=?";
        try {
            PreparedStatement ps = conn.prepareStatement(sql);
            
            ps.setInt(1, newod.getID());
            ps.setDate(2, (Date) newod.getDate());
            ps.setString(3, newod.getAddress());
            ps.setString(4, newod.getPhone());
            ps.setString(5, newod.getProduct());
            ps.setString(6, newod.getPrice());
            ps.setDate(7, (Date) newod.getDeliveryDate());
            ps.setString(8, newod.getStatus());
            ketqua = ps.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(AdminDAOs.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ketqua;
    }
}