Search in sources :

Example 1 with Courses

use of Model.Courses in project Happourse_online_study_web by infiq2000.

the class MyLearning method doGet.

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    int uid = (int) request.getSession(false).getAttribute("uid");
    try {
        List<Courses> ls = courseUtil.listCourse_Id(uid);
        request.setAttribute("listCourses", ls);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    RequestDispatcher dispatcher = request.getRequestDispatcher("/My_learning.jsp");
    dispatcher.forward(request, response);
}
Also used : SQLException(java.sql.SQLException) Courses(Model.Courses) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 2 with Courses

use of Model.Courses in project Happourse_online_study_web by infiq2000.

the class UserPage method doGet.

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    int uid = (int) request.getSession(false).getAttribute("uid");
    User user = null;
    try {
        user = userUtil.getUserbyID(uid);
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    List<Courses> courses;
    try {
        courses = userUtil.getAll_Courses();
        request.setAttribute("listCourses", courses);
        request.setAttribute("user_info", user);
        RequestDispatcher dispatcher = request.getRequestDispatcher("/UserPage.jsp");
        dispatcher.forward(request, response);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : User(Model.User) SQLException(java.sql.SQLException) Courses(Model.Courses) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 3 with Courses

use of Model.Courses in project Happourse_online_study_web by infiq2000.

the class CourseUtil method searchCourseByName.

public List<Courses> searchCourseByName(String name) throws SQLException {
    Connection myConn = null;
    PreparedStatement pstmt = null;
    ResultSet myRS = null;
    List<Courses> li = new ArrayList<>();
    myConn = dataSource.getConnection();
    String sql = "SELECT * FROM happourse.courses c, Happourse.instructor i WHERE c.name like ? AND (c.ins_id = i.ins_id);";
    pstmt = myConn.prepareStatement(sql);
    pstmt.setString(1, "%" + name + "%");
    myRS = pstmt.executeQuery();
    while (myRS.next()) {
        int courses_id = myRS.getInt("course_id");
        String courseName = 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, courseName, skill, price, language, star_rate, description, ins_id, cid, ins_name, major);
        li.add(course);
    }
    myConn.close();
    System.out.println("Tim kiem khoa hoc" + li.size());
    return li;
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) Courses(Model.Courses) PreparedStatement(java.sql.PreparedStatement)

Example 4 with Courses

use of Model.Courses in project Happourse_online_study_web by infiq2000.

the class CourseUtil method getCourseByCategory.

public List<Courses> getCourseByCategory(int cid) throws SQLException {
    Connection myConn = null;
    ResultSet myRS = null;
    myConn = dataSource.getConnection();
    String sql = "SELECT * FROM happourse.courses c, Happourse.instructor i WHERE cid=? AND (c.ins_id = i.ins_id);";
    PreparedStatement pstmt = myConn.prepareStatement(sql);
    pstmt.setInt(1, cid);
    myRS = pstmt.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");
        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 5 with Courses

use of Model.Courses in project Happourse_online_study_web by infiq2000.

the class CourseUtil method getCourseDetail.

public Courses getCourseDetail(int course_id) throws SQLException {
    Connection myConn = null;
    PreparedStatement myStmt = null;
    ResultSet myRS = null;
    myConn = dataSource.getConnection();
    String sql = "select * from courses where course_id = ?";
    myStmt = myConn.prepareStatement(sql);
    myStmt.setInt(1, course_id);
    myRS = myStmt.executeQuery();
    Courses course = null;
    if (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");
        course = new Courses(courses_id, name, skill, price, language, star_rate, description, ins_id, cid);
    }
    myConn.close();
    return course;
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) 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