コード例 #1
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;
     }
   }
 }
コード例 #2
0
 public int addLopMonHoc(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, "");
     stmt.setString(7, "");
     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;
 }