基于JSP+Servlet学生在线选课系统(管理员、教师、学生)
开发工具:eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
//学生课程退选 及 该课程“已选人数”减1
public boolean courseDelete(String sid,String cid) {
if(studentDao.isExistRecord(sid,cid)) { //选修记录存在
return studentDao.courseDelete(sid,cid) & studentDao.cutCourseNum(cid);
}
else {
return false;
}
}
//增加学生选课记录 及 该课程“已选人数”加1
public boolean addChooseCourse(Score score) {
//选修记录不存在 和 可选人数>0 才能增加
if(!studentDao. isExistRecord(score.getsId(),score.getcId())) {
if(studentDao.surplusCount(score.getcId())>0) { // =0:系统异常和可选人数为0
return studentDao.addChooseCourse(score) & studentDao.addCourseNum(score.getcId());
}
else {
return false;
}
}
connection=con.getConnection();
String sql="select cId,cName,credit,period,cPlace,cNumAll,cNum,tName from course,teacher where course.tId=teacher.tId";
pstmt=connection.prepareStatement(sql);
rs=pstmt.executeQuery();
while(rs.next()) {
String cid=rs.getString("cId");
String cname=rs.getString("cName");
String credit=rs.getString("credit");
String period=rs.getString("period");
String cplace=rs.getString("cPlace");
String cnumall=rs.getString("cNumAll");
String cnum=rs.getString("cNum");
String tname=rs.getString("tName");
course=new Course(cid,cname,credit,period,cplace,cnumall,cnum,tname);
courses.add(course);
}
return courses;
}catch(ClassNotFoundException e) {
e.printStackTrace();
}
}
}
//根据教师号删除教师详细信息
public boolean deleteTeadetailByTid(String tid) {
Connection connection=null;
PreparedStatement pstmt=null;
int row;
try{
DBUtil con=new DBUtil();
connection=con.getConnection();
String sql="delete from teadetail where tId=?";
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, tid); //替换上面的?
row=pstmt.executeUpdate();
if(row>0) {
return true;
}
else {
return false;
}
}catch(ClassNotFoundException e) {
}catch(ClassNotFoundException e) {
e.printStackTrace();
return false;
}catch(SQLException e) {
e.printStackTrace();
return false;
}catch(Exception e) {
e.printStackTrace();
return false;
}finally {
try {
}catch(ClassNotFoundException e) {
e.printStackTrace();
return false;
}catch(SQLException e) {
e.printStackTrace();
return false;
}catch(Exception e) {
e.printStackTrace();
return false;
}finally {
try {
if(pstmt!=null)pstmt.close();
if(connection!=null)connection.close();
}catch(SQLException e) {
e.printStackTrace();
}
}
}
#middle{
display:table;
table-layout:fixed;
margin-top:0;
width:100%;
heigth:950px;
}
#nav-wrapper{
margin-top: 2px;
padding: 0.75em;
background-color:#87CEFA;
border-right: 1px solid #bbb;
border-bottom: 1px solid #bbb;
font-size: 10pt;
border-bottom-right-radius: 0px;
box-shadow: 0 0 5px #aaa;
e.printStackTrace();
}
}
}
public boolean isExistAid(String aid) {//true:此人存在 false:此人不存在
return queryByAid(aid)==null? false:true;
}
public Admin queryByAid(String aid) {
Connection connection=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
Admin admin=null;
try{
DBUtil con=new DBUtil();
connection=con.getConnection();
String sql="select * from admin where aId=?";
pstmt=connection.prepareStatement(sql);
connection=con.getConnection();
String sql="delete from choosecourse where sId=?";
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, sid); //替换上面的?
row=pstmt.executeUpdate();
if(row>0) {
return true;
}
else {
return false;
try {
if(rs!=null)rs.close();
if(pstmt!=null)pstmt.close();
if(connection!=null)connection.close();
}catch(SQLException e) {
e.printStackTrace();
}
}
}
//增加学生
public boolean addStudent(Student student1) {
Connection connection=null;
PreparedStatement pstmt=null;
int row;
try{
DBUtil con=new DBUtil();
connection=con.getConnection();
border-collapse: collapse;
text-align: left;
}
#middle > div { display: table-row; }
#middle > div > div { display: table-cell; vertical-align: top; }
#mainLeft {
width: 190px;
transition: width 0.4s;
height:400px;
padding-left: 7px;
padding-top:20px;
<%=course.getPeriod() %> <%=course.getcPlace() %> <%=course.getcNum() %> <% } %> <% }catch(Exception e){ e.printStackTrace(); } %>


