基于web的数据库源码文档格式.docx
- 文档编号:19296968
- 上传时间:2023-01-05
- 格式:DOCX
- 页数:30
- 大小:19.54KB
基于web的数据库源码文档格式.docx
《基于web的数据库源码文档格式.docx》由会员分享,可在线阅读,更多相关《基于web的数据库源码文档格式.docx(30页珍藏版)》请在冰豆网上搜索。
privateStringcourseId="
"
;
//课程ID
privateStringcourseName="
//课程名称
privateStringteacher="
//授课老师姓名
privateintpoint=0;
//学分
privateStringtime1="
//第一节课时间
privateStringtime2="
//第二节课时间
privateStringtime1Express="
//第一节课时间表达式
privateStringtime2Express="
//第二节课时间表达式
privateintlimited=0;
//选课人数
privateintamount=0;
//已选课人数
//空的构造方法
publicCourse()
{
}
//get/set方法
publicStringgetCourseId()
returncourseId;
publicvoidsetCourseId(StringcourseId)
this.courseId=courseId;
publicStringgetCourseName()
returncourseName;
publicvoidsetCourseName(StringcourseName)
this.courseName=courseName;
publicStringgetTeacher()
returnteacher;
publicvoidsetTeacher(Stringteacher)
this.teacher=teacher;
publicintgetPoint()
returnpoint;
publicvoidsetPoint(intpoint)
this.point=point;
publicStringgetTime1()
returntime1;
publicvoidsetTime1(Stringtime1)
this.time1=time1;
this.time1Express=getExpress(time1);
publicStringgetTime1Express()
returntime1Express;
publicStringgetTime2()
returntime2;
publicvoidsetTime2(Stringtime2)
this.time2=time2;
this.time2Express=getExpress(time2);
publicStringgetTime2Express()
returntime2Express;
publicintgetLimited()
returnlimited;
publicvoidsetLimited(intlimited)
this.limited=limited;
publicintgetAmount()
returnamount;
publicvoidsetAmount(intamount)
this.amount=amount;
//根据上课时间拼出实际的时间
publicStringgetExpress(StringcourseTime)
if(courseTime.length()!
=2)
return"
未知上课时间"
StringweekTime=courseTime.substring(0,1);
StringdayTime=courseTime.substring(1,2);
StringweekString="
StringdayString="
if(weekTime.equals("
1"
))
weekString="
星期一"
elseif(weekTime.equals("
2"
星期二"
3"
星期三"
4"
星期四"
5"
星期五"
else
if(dayTime.equals("
dayString="
08:
00~10:
00"
elseif(dayTime.equals("
10:
00~12:
14:
00~16:
16:
00~18:
19:
00~21:
returnweekString+dayString;
}
/*
*Thisproductincludessoftwaredevelopedbythe
*ApacheSoftwareFoundation(http:
//www.apache.org/).
*/
packagech04.servlet;
importjava.io.*;
importjava.util.*;
importjava.sql.*;
importjavax.servlet.*;
importjavax.servlet.http.*;
importch04.*;
/**
*针对教师添加课程页面的Servlet
*@authorShenYK
*@version1.0
publicclassAddCourseextendsCommon
publicvoiddoGet(HttpServletRequestrequest,
HttpServletResponseresponse)
throwsServletException,IOException
//设置提交表单的中文编码
request.setCharacterEncoding("
GBK"
);
HttpSessionmySession=request.getSession(true);
//清空错误消息
mySession.setAttribute("
errMsg"
"
//是否进入默认页面
if(!
request.getParameterNames().hasMoreElements())
//如果是默认进入页面,则单纯显示一个空的页面
Coursecourse=newCourse();
mySession.setAttribute("
course"
course);
response.sendRedirect("
../addCourse.jsp"
return;
//获取表单变量
StringsCourseId=request.getParameter("
courseId"
StringsCourseName=request.getParameter("
courseName"
StringsTeacher=request.getParameter("
teacher"
intiPoint=newInteger(request.getParameter("
point"
)).intValue();
StringsTime1=request.getParameter("
time1D"
)+request.getParameter("
time1T"
StringsTime2=request.getParameter("
time2D"
time2T"
intiLimited=newInteger(request.getParameter("
limited"
CoursenewCourse=newCourse();
newCourse.setCourseId(sCourseId);
newCourse.setCourseName(sCourseName);
newCourse.setTeacher(sTeacher);
newCourse.setPoint(iPoint);
newCourse.setTime1(sTime1);
newCourse.setTime2(sTime2);
newCourse.setLimited(iLimited);
//尝试进行登录
StringsErrMsg=addCourse(newCourse);
//如果登录成功,则跳转到课程一览页面
if(sErrMsg.equals("
))
../servlet/CourseList"
sErrMsg);
newCourse);
publicvoiddoPost(HttpServletRequestrequest,
throwsServletException,IOException
doGet(request,response);
//为用户进行选课
privateStringaddCourse(CoursenewCourse)
//获得数据库连接
Connectionconn=this.getDBConnection();
if(conn==null)
获取数据库连接失败!
Statementstmt=null;
ResultSetrs=null;
try
stmt=conn.createStatement();
//执行SQL语句判断该ID是否已经被使用
StringsQuery="
select*fromcoursewherecourse_id='
+newCourse.getCourseId()+"
'
"
rs=stmt.executeQuery(sQuery);
//检查是否选课人数已满
if(rs.next())
该课程编号已经存在,请重新输入!
StringsUpdateQuery="
insertintocourseset"
+"
course_id='
"
course_name='
+newCourse.getCourseName()+"
teacher='
+newCourse.getTeacher()+"
point="
+newCourse.getPoint()+"
time_1='
+newCourse.getTime1()+"
time_2='
+newCourse.getTime2()+"
limited="
+newCourse.getLimited();
stmt.executeUpdate(sUpdateQuery);
catch(Exceptione)
e.printStackTrace();
登录失败!
finally
rs.close();
stmt.close();
conn.close();
}catch(Exceptionex)
*针对学生选课登录页面的Servlet
publicclassChooseCourseextendsCommon
//如果是默认进入页面,则选出所有备选的课程
StringsUsername=(String)mySession.getAttribute("
username"
);
VectorallCourses=getAllCourses(sUsername);
courses"
allCourses);
../chooseCourse.jsp"
StringsUsername=(String)mySession.getAttribute("
//尝试进行选择
booleanbChoose=chooseCourse(sUsername,sCourseId);
//如果选课成功,则跳转到选课结果一览页面
if(bChoose)
../servlet/ViewCourse"
你选择的课程"
+sCourseId+"
已经满员,请选择其他课程。
//获取用户所有可以使用的课程列表
privateVectorgetAllCourses(StringsUsername)
returnnull;
//执行SQL语句
selectcourse.*,IF(elective.course_id,count(*),0)asamount"
fromcourseleftjoinelective"
oncourse.course_id=elective.course_id"
wherecourse.course_idnotin"
(selectdistinctcourse_idfromelectivewhereusername='
+sUsername+"
)"
groupbycourse.course_id"
//留着在页面上显示的课程列表
Vectorcourses=newVector();
while(rs.next())
course.setCourseId(rs.getString("
course_id"
));
course.setCourseName(rs.getString("
course_name"
course.setTeacher(rs.getString("
course.setPoint(
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 web 数据库 源码