Esempio n. 1
0
  public ArrayList<GioHocEntity> getAllGioHoc() throws Exception {
    ArrayList<GioHocEntity> arrGioHoc = new ArrayList<GioHocEntity>();
    Statement stmt = null;
    ResultSet rs = null;
    Connection cn = null;
    try {
      cn = DBPool.getConnection();
      stmt = cn.createStatement();
      String SQL = "SELECT * FROM GIOHOC ORDER BY MaGioHoc ASC";
      rs = stmt.executeQuery(SQL);

      while (rs.next()) {
        GioHocEntity gioHoc = new GioHocEntity();
        gioHoc.setMaGioHoc(rs.getString(1));
        gioHoc.setThoiGian(rs.getString(2));
        arrGioHoc.add(gioHoc);
      }
    } catch (Exception ex) {
      throw ex;
    } finally {
      try {
        DBPool.releaseConnection(cn, stmt, rs);
      } catch (Exception e) {
        throw e;
      }
    }

    return arrGioHoc;
  }
Esempio n. 2
0
  public ArrayList<PhongHocEntity> getAllPhongHoc() throws Exception {
    ArrayList<PhongHocEntity> arrPhongHoc = new ArrayList<PhongHocEntity>();
    Statement stmt = null;
    ResultSet rs = null;
    Connection cn = null;
    try {
      cn = DBPool.getConnection();
      stmt = cn.createStatement();
      String SQL = "SELECT * FROM PHONGHOC";
      rs = stmt.executeQuery(SQL);

      while (rs.next()) {
        PhongHocEntity phongHoc = new PhongHocEntity();
        phongHoc.setMaPhongHoc(rs.getString(1));
        phongHoc.setTenPhongHoc(rs.getString(2));

        arrPhongHoc.add(phongHoc);
      }
    } catch (Exception ex) {
      throw ex;
    } finally {
      try {
        DBPool.releaseConnection(cn, stmt, rs);
      } catch (Exception e) {
        throw e;
      }
    }

    return arrPhongHoc;
  }
Esempio n. 3
0
 public String getTenPhongHoc(String Ma) throws Exception {
   String Ten = "";
   PreparedStatement stmt = null;
   Connection conn = null;
   ResultSet rs = null;
   try {
     String SQL = "SELECT TenPhongHoc FROM PHONGHOC WHERE MaPhongHoc = ?";
     conn = DBPool.getConnection();
     stmt = conn.prepareStatement(SQL);
     stmt.setString(1, Ma);
     rs = stmt.executeQuery();
     while (rs.next()) {
       Ten = rs.getString(1);
     }
   } catch (Exception ex) {
     throw ex;
   } finally {
     try {
       DBPool.releaseConnection(conn, stmt, rs);
     } catch (Exception e) {
       throw e;
     }
   }
   return Ten;
 }
Esempio n. 4
0
  public boolean checkDuplicateThoiKhoaBieu(String MaLop, String MaMon) throws Exception {

    PreparedStatement stmt = null;
    Connection conn = null;
    ResultSet rs = null;
    try {
      String SQL = "SELECT * from LOPMONHOC WHERE MaLop = ? AND MaMonHoc = ?";
      conn = DBPool.getConnection();
      stmt = conn.prepareStatement(SQL);
      stmt.setString(1, MaLop);
      stmt.setString(2, MaMon);
      rs = stmt.executeQuery();
      while (rs.next()) {
        return true;
      }
    } catch (Exception ex) {
      throw ex;
    } finally {
      try {
        DBPool.releaseConnection(conn, stmt, rs);
      } catch (Exception e) {
        throw e;
      }
    }
    return false;
  }
Esempio n. 5
0
  public ArrayList<LopMonHocEntity> getAllLopMonHoc() throws Exception {
    ArrayList<LopMonHocEntity> arrLopMonHoc = new ArrayList<LopMonHocEntity>();
    Statement stmt = null;
    ResultSet rs = null;
    Connection cn = null;
    SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
    try {
      cn = DBPool.getConnection();
      stmt = cn.createStatement();
      String SQL =
          "SELECT LOPMONHOC.*, MONHOC.TenMonHoc, MONHOC.SoGio, LOPHOC.TenLop, GIOHOC.ThoiGian, PHONGHOC.TenPhongHoc FROM LOPMONHOC"
              + " INNER JOIN MONHOC ON LOPMONHOC.MaMonHoc = MONHOC.MaMonHoc"
              + " INNER JOIN LOPHOC ON LOPMONHOC.MaLop = LOPHOC.MaLop"
              + " INNER JOIN GIOHOC ON LOPMONHOC.MaGioHoc = GIOHOC.MaGioHoc"
              + " INNER JOIN PHONGHOC ON LOPMONHOC.MaPhong = PHONGHOC.MaPhongHoc";
      rs = stmt.executeQuery(SQL);

      while (rs.next()) {
        LopMonHocEntity lopMonHoc = new LopMonHocEntity();
        lopMonHoc.setIdLopMonHoc(Integer.parseInt(rs.getString(1)));
        lopMonHoc.setMaMonHoc(rs.getString(2));
        lopMonHoc.setMaLop(rs.getString(3));
        lopMonHoc.setMaGioHoc(rs.getString(4));
        lopMonHoc.setMaPhong(rs.getString(5));
        lopMonHoc.setNgayBatDauHoc(rs.getDate(6));
        lopMonHoc.setNgayBatDauHocView(format.format(rs.getDate(6)));
        lopMonHoc.setNgayNghiDKBatDau(rs.getDate(7));
        lopMonHoc.setNgayNghiDKBatDauView(format.format(rs.getDate(7)));
        lopMonHoc.setNgayNghiDKKetThuc(rs.getDate(8));
        lopMonHoc.setNgayNghiDKKetThucView(format.format(rs.getDate(8)));
        lopMonHoc.setNgayHoc(rs.getString(9));
        lopMonHoc.setGiangVien(rs.getString(10));
        lopMonHoc.setNgayThiDuKienView(format.format(rs.getDate(11)));
        lopMonHoc.setTenMonHoc(rs.getString(12));
        lopMonHoc.setSoGio(Integer.parseInt(rs.getString(13)));
        lopMonHoc.setTenLop(rs.getString(14));
        lopMonHoc.setThoiGian(rs.getString(15));
        lopMonHoc.setTenPhongHoc(rs.getString(16));
        arrLopMonHoc.add(lopMonHoc);
      }
    } catch (Exception ex) {
      throw ex;
    } finally {
      try {
        DBPool.releaseConnection(cn, stmt, rs);
      } catch (Exception e) {
        throw e;
      }
    }

    return arrLopMonHoc;
  }
Esempio n. 6
0
  public void deleteLopMonHoc(ArrayList<LopMonHocEntity> arr) throws SQLException, Exception {
    PreparedStatement stmt = null;
    Connection conn = null;
    try {
      conn = DBPool.getConnection();
      conn.setAutoCommit(false); // tao transaction
      for (LopMonHocEntity lopHoc : arr) {
        String SQL = "delete LOPMONHOC  where idLopMonHoc = ? ";
        stmt = conn.prepareStatement(SQL);
        stmt.setInt(1, lopHoc.getIdLopMonHoc());
        stmt.executeUpdate();
      }
      conn.commit();

    } catch (Exception ex) {
      conn.rollback();
      conn.setAutoCommit(true);
      throw new Exception(ex.getMessage());

    } finally {

      DBPool.releaseConnection(conn, stmt);
    }
  }