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);
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations