Exemplo n.º 1
0
 public int addLopMonHocNgayNghi(LopMonHocEntity lopMonHoc) throws SQLException {
   int id = 0;
   PreparedStatement stmt = null;
   Connection conn = null;
   SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
   try {
     String SQL = "insert into LOPMONHOC values(?,?,?,?,?,?,?,?,?,?)";
     conn = DBPool.getConnection();
     stmt = conn.prepareStatement(SQL, Statement.RETURN_GENERATED_KEYS);
     stmt.setString(1, lopMonHoc.getMaMonHoc());
     stmt.setString(2, lopMonHoc.getMaLop());
     stmt.setString(3, lopMonHoc.getMaGioHoc());
     stmt.setString(4, lopMonHoc.getMaPhong());
     stmt.setString(5, format.format(lopMonHoc.getNgayBatDauHoc()));
     stmt.setString(6, format.format(lopMonHoc.getNgayNghiDKBatDau()));
     stmt.setString(7, format.format(lopMonHoc.getNgayNghiDKKetThuc()));
     stmt.setString(8, lopMonHoc.getNgayHoc());
     stmt.setString(9, lopMonHoc.getGiangVien());
     stmt.setString(10, format.format(lopMonHoc.getNgayThiDuKien()));
     stmt.executeUpdate();
     ResultSet rs = stmt.getGeneratedKeys();
     rs.next();
     id = rs.getInt(1);
     System.out.println("ID: " + id);
   } finally {
     try {
       stmt.close();
       conn.close();
     } catch (SQLException ex) {
       throw ex;
     }
   }
   return id;
 }
Exemplo n.º 2
0
 public void editLopMonHocFull(LopMonHocEntity lop) throws SQLException {
   PreparedStatement stmt = null;
   Connection conn = null;
   SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
   try {
     String SQL =
         "update LOPMONHOC set MaGioHoc = ?, MaPhong = ?, NgayBatDauHoc = ?, NgayNghiDKBatDau = ?, NgayNghiDKKetThuc = ?, NgayHoc = ?, GiangVien = ?, NgayThiDuKien = ? WHERE IdLopMonHoc = ?";
     conn = DBPool.getConnection();
     stmt = conn.prepareStatement(SQL);
     stmt.setString(1, lop.getMaGioHoc());
     //            stmt.setString(2, format.format(sv.getNgaySinh()));
     stmt.setString(2, lop.getMaPhong());
     stmt.setString(3, format.format(lop.getNgayBatDauHoc()));
     stmt.setString(4, format.format(lop.getNgayNghiDKBatDau()));
     stmt.setString(5, format.format(lop.getNgayNghiDKKetThuc()));
     stmt.setString(6, lop.getNgayHoc());
     stmt.setString(7, lop.getGiangVien());
     stmt.setString(8, format.format(lop.getNgayThiDuKien()));
     stmt.setInt(9, lop.getIdLopMonHoc());
     stmt.executeUpdate();
   } finally {
     try {
       stmt.close();
       conn.close();
     } catch (SQLException ex) {
       throw ex;
     }
   }
 }
Exemplo n.º 3
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);
    }
  }
Exemplo n.º 4
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;
  }