Search in sources :

Example 11 with Courses

use of Model.Courses in project Happourse_online_study_web by infiq2000.

the class TakeCourse method doGet.

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    int course_id = Integer.parseInt(request.getParameter("course_id"));
    try {
        Courses detailC = courseUtil.getCourseDetail(course_id);
        request.setAttribute("course_detail", detailC);
        String cate = insUtil.getCate(detailC.getCid());
        request.setAttribute("cate", cate);
        Instructor ins_info = insUtil.getIns_Info(detailC.getIns_id());
        request.setAttribute("ins_info", ins_info);
        request.setAttribute("course_id", course_id);
        RequestDispatcher dispatcher = request.getRequestDispatcher("/takecourse.jsp");
        dispatcher.forward(request, response);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) Instructor(Model.Instructor) Courses(Model.Courses) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 12 with Courses

use of Model.Courses in project Happourse_online_study_web by infiq2000.

the class CourseUtil method checkSignedCourse.

public Courses checkSignedCourse(int course_id, int uid) throws SQLException {
    Connection myConn = null;
    ResultSet myRS = null;
    myConn = dataSource.getConnection();
    String sql = "SELECT * FROM happourse.user_course c WHERE uid=? AND course_id=?;";
    PreparedStatement pstmt = myConn.prepareStatement(sql);
    pstmt.setInt(1, uid);
    pstmt.setInt(2, course_id);
    myRS = pstmt.executeQuery();
    Courses course;
    if (myRS.next()) {
        course = getCourseDetail(course_id);
        myConn.close();
        return course;
    } else {
        myConn.close();
        return null;
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Courses(Model.Courses) PreparedStatement(java.sql.PreparedStatement)

Example 13 with Courses

use of Model.Courses in project Happourse_online_study_web by infiq2000.

the class CourseUtil method listCourse_Id.

public List<Courses> listCourse_Id(int uid) throws SQLException {
    Connection myConn = null;
    PreparedStatement myStmt = null;
    ResultSet myRS = null;
    myConn = dataSource.getConnection();
    String sql = "SELECT * FROM Happourse.courses c, Happourse.instructor i WHERE c.ins_id = i.ins_id  AND c.course_id IN ( SELECT course_id FROM Happourse.user_course WHERE uid = ?)";
    myStmt = myConn.prepareStatement(sql);
    myStmt.setInt(1, uid);
    myRS = myStmt.executeQuery();
    List<Courses> ls = new ArrayList<>();
    while (myRS.next()) {
        int courses_id = myRS.getInt("course_id");
        String name = myRS.getString("name");
        String skill = myRS.getString("skill");
        int price = myRS.getInt("price");
        String language = myRS.getString("language");
        String description = myRS.getString("description");
        double star_rate = myRS.getDouble("star_rate");
        int ins_id = myRS.getInt("ins_id");
        int cid = myRS.getInt("cid");
        String ins_name = myRS.getString("ins_name");
        String major = myRS.getString("major");
        Courses course = new Courses(courses_id, name, skill, price, language, star_rate, description, ins_id, cid, ins_name, major);
        ls.add(course);
    }
    myConn.close();
    return ls;
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) Courses(Model.Courses) PreparedStatement(java.sql.PreparedStatement)

Example 14 with Courses

use of Model.Courses in project Happourse_online_study_web by infiq2000.

the class UserUtil method getAll_Courses.

public List<Courses> getAll_Courses() throws SQLException {
    Connection myConn = null;
    PreparedStatement myStmt = null;
    ResultSet myRS = null;
    myConn = dataSource.getConnection();
    String sql = "select * from courses ";
    myStmt = myConn.prepareStatement(sql);
    myRS = myStmt.executeQuery();
    List<Courses> courses = new ArrayList<>();
    while (myRS.next()) {
        int courses_id = myRS.getInt("course_id");
        String name = myRS.getString("name");
        String skill = myRS.getString("skill");
        int price = myRS.getInt("price");
        String language = myRS.getString("language");
        String description = myRS.getString("description");
        double star_rate = myRS.getDouble("star_rate");
        int ins_id = myRS.getInt("ins_id");
        int cid = myRS.getInt("cid");
        courses.add(new Courses(courses_id, name, skill, price, language, star_rate, description, ins_id, cid));
    }
    return courses;
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) Courses(Model.Courses) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Courses (Model.Courses)14 RequestDispatcher (javax.servlet.RequestDispatcher)8 SQLException (java.sql.SQLException)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 ArrayList (java.util.ArrayList)4 Instructor (Model.Instructor)3 Account (Model.Account)2 Chapter (Model.Chapter)2 User (Model.User)2 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 HttpSession (javax.servlet.http.HttpSession)1