Exemple #1
0
 public Course getCourseByCode(String code) {
   Course course = null;
   PreparedStatement selectStatement;
   try {
     String query = "SELECT * FROM COURSE WHERE COURSECODE = ?";
     selectStatement = ConnectionUtil.getOracleConnection().prepareStatement(query);
     selectStatement.setMaxRows(1);
     selectStatement.setString(1, code);
     ResultSet rs = selectStatement.executeQuery();
     while (rs.next())
       course =
           CourseBuilder.createCourseBuilder()
               .setId(rs.getInt("COURSEID"))
               .setCode(rs.getString("COURSECODE"))
               .setTitle(rs.getString("TITLE"))
               .buildCourse();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return course;
 }
Exemple #2
0
 private List<CourseInstance> resultSetToList(ResultSet rs) throws SQLException {
   List<CourseInstance> instances = new ArrayList<>();
   Course course;
   CourseInstance courseInstance;
   while (rs.next()) {
     course =
         CourseBuilder.createCourseBuilder()
             .setId(rs.getInt("COURSEID"))
             .setCode(rs.getString("COURSECODE"))
             .setTitle(rs.getString("TITLE"))
             .buildCourse();
     courseInstance =
         CourseInstanceBuilder.createCourseBuilder()
             .setId(rs.getInt("INSTANCEID"))
             .setDurance(rs.getInt("DURANCE"))
             .setStartDate(rs.getDate("STARTDATE"))
             .setCourse(course)
             .setPrice(rs.getDouble("PRICE"))
             .buildCourseInstance();
     instances.add(courseInstance);
   }
   return instances;
 }