基于javaweb+JSP+Servlet学生在线选课系统(管理员、教师、学生)
开发工具:eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
row=pstmt.executeUpdate();
if(row>0) {
return true;
}
else {
return false;
}
}catch(ClassNotFoundException e) {
e.printStackTrace();
return false;
}catch(SQLException e) {
e.printStackTrace();
return false;
}catch(Exception e) {
e.printStackTrace();
return false;
}finally {
try {
if(!result) { //注册失败
request.setAttribute("error", "addError");
}
else { //注册成功
request.setAttribute("error", "addSuccess");
}
request.getRequestDispatcher("addcourse.jsp").forward(request, response); //StudentQueryAllServlet直接转发给StudentInfoList.jsp,不需要进行处理
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
return null;
}catch(Exception e) {
e.printStackTrace();
return null;
}finally {
try {
if(rs!=null)rs.close();
if(pstmt!=null)pstmt.close();
if(connection!=null)connection.close();
}catch(SQLException e) {
e.printStackTrace();
}
}
}
//录入成绩
public boolean addGrade(Grade grade) {
Connection connection=null;
PreparedStatement pstmt=null;
int row;
try{
DBUtil con=new DBUtil();
connection=con.getConnection();
String sql="update choosecourse set grade=? where sId=? and cId=?";
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, sid);
rs=pstmt.executeQuery();
while(rs.next()) {
String cid=rs.getString("choosecourse.cId");
String cname=rs.getString("cName");
String credit=rs.getString("credit");
String period=rs.getString("period");
String cplace=rs.getString("cPlace");
String tname=rs.getString("tName");
course=new Course(cid,cname,credit,period,cplace,tname);
courses.add(course);
}
return courses;
}catch(Exception e) {
e.printStackTrace();
return null;
}finally {
try {
if(rs!=null)rs.close();
if(pstmt!=null)pstmt.close();
if(connection!=null)connection.close();
}catch(SQLException e) {
e.printStackTrace();
}
}
}



