示例#1
0
  @Override
  public void addCourse(Course add1, String addPres) {
    // TODO Auto-generated method stub

    try {
      stmt =
          conn.prepareStatement(
              "INSERT INTO Course(courseNo,courseName,credits,preCourseNos) VALUES(?,?,?,?)");
      stmt.setString(1, add1.getCourseNo());
      stmt.setString(2, add1.getCourseName());
      stmt.setDouble(3, add1.getCredits());
      stmt.setString(4, addPres);

      stmt.executeUpdate();
    } catch (SQLException e) {
      ex = e;
    } finally {
      if (conn != null) {
        try {
          conn.close();
        } catch (SQLException e) {
          if (ex == null) {
            ex = e;
          }
        }
      }
      if (ex != null) {
        throw new RuntimeException(ex);
      }
    }
  }
示例#2
0
  @Override
  public void updateCourses(Course ud, String changePres) {
    // TODO Auto-generated method stub
    try {

      stmt =
          conn.prepareStatement(
              "update Course set courseName=?,credits=?,preCourseNos=? where courseNo=?");
      stmt.setString(1, ud.getCourseName());
      stmt.setDouble(2, ud.getCredits());
      stmt.setString(3, changePres);
      stmt.setString(4, ud.getCourseNo());

      stmt.executeUpdate();
    } catch (SQLException e) {
      ex = e;
    } finally {
      if (conn != null) {
        try {
          conn.close();
        } catch (SQLException e) {
          if (ex == null) {
            ex = e;
          }
        }
      }
      if (ex != null) {
        throw new RuntimeException(ex);
      }
    }
  }