开发工具:eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
}
#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;
}
#middle{
display:table;
table-layout:fixed;
background-color:#6495ED;
margin-top:0;
width:100%;
heigth:950px;
}
#nav-wrapper{
margin-top: 2px;
padding: 0.75em;
background-color:#ADD8E6;
border-right: 1px solid #bbb;
if(rs!=null)rs.close();
if(pstmt!=null)pstmt.close();
if(connection!=null)connection.close();
}catch(SQLException e) {
e.printStackTrace();
}
}
}
//查询空闲教室
public List<Room> roomQuery() {
Connection connection=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
Room room=null;
List<Room>rooms=new ArrayList<Room>();
try{
DBUtil con=new DBUtil();
connection=con.getConnection();
String sql="select * from room";
pstmt=connection.prepareStatement(sql);
rs=pstmt.executeQuery();
while(rs.next()) {
String rname=rs.getString("roomName");
String rnum=rs.getString("roomNum");
String rtime=rs.getString("roomTime");
room=new Room(rname,rnum,rtime);
}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 List<Course> courseQuery(String sid) {
Connection connection=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
Course course=null;
List<Course>courses=new ArrayList<Course>();
try{
DBUtil con=new DBUtil();
connection=con.getConnection();
String sql="select choosecourse.cId,cName,credit,period,cPlace,tName from choosecourse,course,teacher where choosecourse.cId=course.cId and course.tId=teacher.tId and sId=?";
pstmt=connection.prepareStatement(sql);
td{text-align:center}
</style>
<style type="text/css">
body, input {
font-family: 'Open Sans', sans-serif;
font-size: 10.5pt;
}
table {
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;
}
}
}
public boolean isExistCourse(String cid,String tid) {//true:此人存在 false:此人不存在
return queryByCid(cid,tid)==null? false:true;
}
public Course queryByCid(String cid, String tid) {
Connection connection=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
Course course=null;
try{
DBUtil con=new DBUtil();
connection=con.getConnection();
String sql="select * from course where cId=? and tId=?";
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, cid); //替换上面的?
pstmt.setString(2, tid);
rs=pstmt.executeQuery();
if(rs.next()) { //只有一条数据,不用循环
String cId=rs.getString("cId");
String cName=rs.getString("cName");
String tId=rs.getString("tId");
String credit=rs.getString("credit");
String period=rs.getString("period");
String cPlace=rs.getString("cPlace");
this.tName = tName;
this.tPass = tPass;
this.dId = dId;
this.tSex = tSex;
this.tAge = tAge;
this.tEdu = tEdu;
this.tTitle=tTitle;
this.tSch=tSch;
this.tHealth=tHealth;
}
public String gettId() {
return tId;
}
public void settId(String tId) {
this.tId = tId;
}
public String gettName() {
return tName;
}
public void settName(String tName) {
this.tName = tName;
}
public String gettPass() {
return tPass;
}
public void settPass(String tPass) {
this.tPass = tPass;
<div id="mainLeft">
<div id="nav-wrapper">
<nav>
<div>
<h2 id="hea">学生选课系统</h2><br>
<ul>
<li>
<a href="TeaQueryByTidServlet?tid=<%=(String)session.getAttribute("id")%>">个人信息</a><hr>
</li>
<li>
<a href="teacherMod.jsp">密码修改</a><hr>
</li>
<li>
<a href="TeaAllCourseQueryServlet?tid=<%=(String)session.getAttribute("id")%>">录入成绩</a><hr>
</li>
<li>
<a href="TeaLookcourseQueryServlet?tid=<%=(String)session.getAttribute("id")%>">查询选课</a><hr>
</li>
<li>
<a href="classroom.jsp">查询教室</a><hr>
</li>
<li>
<a href="TeaDeleteServlet?tid=<%=(String)session.getAttribute("id")%>">注销</a><hr>
</li>
</ul>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</div>
</nav>
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(pstmt!=null)pstmt.close();
if(connection!=null)connection.close();
}catch(SQLException 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();
}
}
}
//注销前删除该学生的所有选课记录,解决外码约束无法注销的问题
pstmt.setString(1, cid);
rs=pstmt.executeQuery();
if(rs.next()) { //只有一条数据,不用循环
String numall=rs.getString("cNumAll");
String num=rs.getString("cNum");
count=Integer.parseInt(numall)-Integer.parseInt(num);
}
return count;
}catch(ClassNotFoundException e) {
e.printStackTrace();
return 0;
}catch(SQLException e) {
e.printStackTrace();
return 0;
}catch(Exception e) {
e.printStackTrace();
return 0;
}finally {
try {
if(rs!=null)rs.close();
}
public String gettPass() {
return tPass;
}
public void settPass(String tPass) {
this.tPass = tPass;
}
public String getdId() {
return dId;
}
public void setdId(String dId) {
this.dId = dId;
}
public String gettSex() {
return tSex;
<tr>
<td>年龄:</td>
<td><input type="text" name="tAge"></td>
</tr>
<tr>
<td>学历:</td>
<td><input type="text" name="tEdu"></td>
</tr>
<tr>
<td>职称:</td>
<td><input type="text" name="tTitle"></td>
</tr>
<tr>
<td>毕业院校:</td>
<td><input type="text" name="tSch"></td>
</tr>
<tr>
<td>健康状况:</td>
<td><input type="text" name="tHealth"></td>
</tr>
<tr><td><input type="submit" value="确认"/></td></tr>
</table>
</form>
</center>
</div>
DBUtil con=new DBUtil();
connection=con.getConnection();
String sql="delete from student where sId=?";
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, sid); //替换上面的?
row=pstmt.executeUpdate();
if(row>0) {
return true;
}
else {
return false;
}
}catch(ClassNotFoundException e) {
e.printStackTrace();
return false;
}catch(SQLException e) {
e.printStackTrace();
else {
return false;
}
}
//根据学号注销学生
public boolean deleteBySid(String sid) {
if(studentDao.isExist(sid)) { //学生存在
studentDao.deleteRecordBySid(sid); //先删除该学生的所有选课记录
return studentDao.deleteStuBySid(sid) && studentDao.deleteStudetailBySid(sid);
}
else {
return false;
}
}
}
package com.demo.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
<li>
<a href="stuMessMod.jsp">密码修改</a><hr>
</li>
<li>
<a href="StuGradeQueryServlet?sid=<%=(String)session.getAttribute("id")%>">成绩查询</a><hr>
</li>
<li>
<a href="StuCourseQueryServlet?sid=<%=(String)session.getAttribute("id")%>">选课查询以及退选</a><hr>
</li>
<li>
<a href="StuAllCourseQueryServlet">选课</a><hr>
</li>
<li>
<a href="StuDeleteServlet?sid=<%=(String)session.getAttribute("id")%>">注销</a><hr>
</li>
</ul>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</div>
String sql="select teacher.*,teadetail.* from teacher,teadetail where teacher.tId=teadetail.tId and teacher.tId=?";
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, tid); //替换上面的?
rs=pstmt.executeQuery();
if(rs.next()) { //只有一条数据,不用循环
String tId=rs.getString("teacher.tId");
String tName=rs.getString("tName");
String tPass=rs.getString("tPass");
String dId=rs.getString("dId");
String tSex=rs.getString("tSex");
String tAge=rs.getString("tAge");
String tEdu=rs.getString("tEdu");
String tTitle=rs.getString("tTitle");
String tSch=rs.getString("tSch");
String tHealth=rs.getString("tHealth");
if(!result) { //注册失败
request.setAttribute("error", "addError");
}
else { //注册成功
request.setAttribute("error", "addSuccess");
}
request.getRequestDispatcher("addstudent.jsp").forward(request, response); //StudentQueryAllServlet直接转发给StudentInfoList.jsp,不需要进行处理
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
package com.demo.vo;
//删除管理员
public boolean deleteAdminByAid(String aid) {
Connection connection=null;
PreparedStatement pstmt=null;
int row;
try{
DBUtil con=new DBUtil();
connection=con.getConnection();
String sql="delete from admin where aId=?";
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, aid); //替换上面的?
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 {
}
}
package com.demo.service;
import java.util.List;
import com.demo.dao.StudentDao;
import com.demo.vo.Course;
import com.demo.vo.Score;
import com.demo.vo.Student;
//业务逻辑层(逻辑性的增删改)(如 增:查+增 对Dao层进行的组装)
public class StudentService {
StudentDao studentDao=new StudentDao();
//根据学号查询学生个人信息
public Student queryBySid(String sid) {
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;
heigth:400px;
}
#nav-wrapper1{
margin-top: 2px;
padding: 0.75em;
}
}
}
//增加学生
public boolean addStudent(Student student1) {
Connection connection=null;
PreparedStatement pstmt=null;
int row;
try{
DBUtil con=new DBUtil();
connection=con.getConnection();
String sql="insert into student(sId,sName,sPass,dId) values(?,?,?,?)";
pstmt=connection.prepareStatement(sql);
pstmt.setString(1, student1.getsId()); //替换上面第一个?
pstmt.setString(2, student1.getsName()); //替换上面第二个?
pstmt.setString(3, student1.getsPass());
pstmt.setString(4, student1.getdId());
运行环境
Java≥8、Tomcat≥7.0、MySQL≥5.5
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
CSS JavaScript JSP Servlet JDBC MySQL
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
管理员:个人信息、学生、老师、学生、课程等管理
教师:个人信息、成绩、选课管理、教室查看
学生:个人信息、成绩查看、选课和查看
eclipse或MyEclipse或idea
管理员
学生
教师