javaee大作业.docx
- 文档编号:8460625
- 上传时间:2023-01-31
- 格式:DOCX
- 页数:37
- 大小:7.12MB
javaee大作业.docx
《javaee大作业.docx》由会员分享,可在线阅读,更多相关《javaee大作业.docx(37页珍藏版)》请在冰豆网上搜索。
javaee大作业
《Javaee程序设计》课程期末作业
题目学生学籍管理系统
学院计算机学院
专业计算机科学与技术
班别13级
(2)班
学号********
姓名
2016年5月22日
一、运行结果:
输入账号jax密码123456
显示教师端登录成功:
点击查看所有学生信息:
点击按学号查询,输入学号001:
结果显示:
点击按学号删除学生,输入学号001:
显示删除成功
点击更新学生年龄,输入学号002和年龄50
结果显示修改成功:
点击添加学生信息,并输入新学生信息如下:
结果显示添加成功:
最后再次查询所有学生来显示前面操作的效果:
倘若登录界面输入学号jack和密码******,则学生端登录成功,只有部分功能:
如下图:
二、代码部分:
链接数据库部分
packagecn.dbc;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.PreparedStatement;
importjava.sql.ResultSet;
publicclassBaseDao
{
/*
*数据库连接信息
*/
publicConnectiongetConnection()
{
Connectionconn=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:
mysql:
//localhost:
3306/MySchool","root","123456");
}
catch(Exceptione)
{
e.printStackTrace();
}
returnconn;
}
publicvoidcloseConn(Connectionconn,PreparedStatementpstmt,ResultSetrs)
{
try
{
if(rs!
=null)
{
rs.close();
}
if(pstmt!
=null)
{
pstmt.close();
}
if(conn!
=null)
{
conn.close();
}
}
catch(Exceptionex)
{
System.out.println(ex.getMessage());
}
}
publicvoidcloseConn(Connectionconn,PreparedStatementpstmt)
{
try
{
if(pstmt!
=null)
{
pstmt.close();
}
if(conn!
=null)
{
conn.close();
}
}
catch(Exceptionex)
{
System.out.println(ex.getMessage());
}
}
}
学生实体类:
packagecn.bean;
publicclassStudent
{
privateStringid;
privateStringname;
privateStringsex;
privateintage;
privateStringcollage;
privateStringgrade;
publicStringgetId()
{
returnid;
}
publicvoidsetId(Stringid)
{
this.id=id;
}
publicStringgetName()
{
returnname;
}
publicvoidsetName(Stringname)
{
this.name=name;
}
publicStringgetSex()
{
returnsex;
}
publicvoidsetSex(Stringsex)
{
this.sex=sex;
}
publicintgetAge()
{
returnage;
}
publicvoidsetAge(intage)
{
this.age=age;
}
publicStringgetCollage()
{
returncollage;
}
publicvoidsetCollage(Stringcollage)
{
this.collage=collage;
}
publicStringgetGrade()
{
returngrade;
}
publicvoidsetGrade(Stringgrade)
{
this.grade=grade;
}
publicStudent(Stringid,Stringname,Stringsex,intage,Stringcollage,Stringgrade)
{
super();
this.id=id;
this.name=name;
this.sex=sex;
this.age=age;
this.collage=collage;
this.grade=grade;
}
publicStudent()
{
super();
}
}
对数据的增删查改实现的代码:
packagecn.dao.impl;
importjava.sql.Connection;
importjava.sql.PreparedStatement;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.util.ArrayList;
importjava.util.List;
importcn.bean.Student;
importcn.dao.StudentDao;
importcn.dbc.BaseDao;
publicclassStudentDaoImplimplementsStudentDao
{
BaseDaobs=newBaseDao();
Connectionconn=null;
PreparedStatementpstmt=null;
publicArrayList
{
//查看整个学生表
ArrayList
Stringsql="select*fromstudent";
ResultSetrs=null;
conn=bs.getConnection();
try
{
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
System.out.println("学号"+"\t"+"姓名"+"\t"+"年龄"+"\t"+"性别"+"\t"+"年级"+"\t"+"学院"+"\t");
while(rs.next())
{
Studentstu=newStudent();
stu.setId(rs.getString
(1));
stu.setName(rs.getString
(2));
stu.setAge(rs.getInt(3));
stu.setSex(rs.getString(4));
stu.setGrade(rs.getString(5));
stu.setCollage(rs.getString(6));
AL.add(stu);
}
for(inti=0;i { System.out.println(AL.get(i).getId()+"\t"+AL.get(i).getName()+"\t"+AL.get(i).getAge()+"\t"+AL.get(i).getSex()+"\t"+AL.get(i).getGrade()+"\t"+AL.get(i).getCollage()); } } catch(SQLExceptione) { //TODO自动生成的catch块 e.printStackTrace(); } finally { bs.closeConn(conn,pstmt,rs); } returnAL; } publicStudentfindStudent(Stringid) { //根据学号查找学生 Studentstu=newStudent(); conn=bs.getConnection(); ResultSetrs=null; Stringsql="select*fromstudentwhereid=? "; try { pstmt=conn.prepareStatement(sql); pstmt.setString(1,id); rs=pstmt.executeQuery(); System.out.println("学号"+"\t"+"姓名"+"\t"+"年龄"+"\t"+"性别"+"\t"+"年级"+"\t"+"学院"+"\t"); while(rs.next()) { stu.setId(id); stu.setName(rs.getString (2)); stu.setAge(rs.getInt(3)); stu.setSex(rs.getString(4)); stu.setGrade(rs.getString(5)); stu.setCollage(rs.getString(6)); } System.out.println(stu.getId()+"\t"+stu.getName()+"\t"+stu.getAge()+"\t"+stu.getSex()+"\t"+stu.getGrade()+"\t"+stu.getCollage()); } catch(SQLExceptione) { //TODO自动生成的catch块 e.printStackTrace(); } finally { bs.closeConn(conn,pstmt,rs); } returnstu; } publicbooleandelStudent(Stringid)//根据id删除学生信息 { booleanisflag=false; conn=bs.getConnection(); Stringsql="deletefromstudentwhereid=? "; try { pstmt=conn.prepareStatement(sql); pstmt.setString(1,id); intnum=pstmt.executeUpdate(); if(num>0) { isflag=true; System.out.println("删除成功! "); System.out.println("------------------"); } }catch(SQLExceptione) { //TODO自动生成的catch块 e.printStackTrace(); } finally { bs.closeConn(conn,pstmt); } returnisflag; } publicbooleanaddStudent(Stringid,Stringname,Stringage,Stringsex,Stringgrade,Stringcollage)//添加学生信息 { booleanisflag=false; conn=bs.getConnection(); Stringsql="insertintostudentvalues(? ? ? ? ? ? )"; try { pstmt=conn.prepareStatement(sql); pstmt.setString(1,id); pstmt.setString(2,name); pstmt.setString(3,age); pstmt.setString(4,sex); pstmt.setString(5,grade); pstmt.setString(6,collage); intnum=pstmt.executeUpdate(); if(num>0) { isflag=true; System.out.println("添加成功! "); System.out.println("------------------"); } }catch(SQLExceptione) { //TODO自动生成的catch块 e.printStackTrace(); } finally { bs.closeConn(conn,pstmt); } returnisflag; } publicbooleanupdateStudent(Stringid,Stringage)//根据学号修改学生年龄 { booleanisflag=false; conn=bs.getConnection(); Stringsql="updatestudentsetage=? whereid=? "; try { pstmt=conn.prepareStatement(sql); pstmt.setString(2,id); pstmt.setString(1,age); intnum=pstmt.executeUpdate(); if(num>0) { isflag=true; System.out.println("更新成功! "); System.out.println("------------------"); } }catch(SQLExceptione) { //TODO自动生成的catch块 e.printStackTrace(); } finally { bs.closeConn(conn,pstmt); } returnisflag; } } 登录类: publicclassUserImplimplementsUser { BaseDaobs=newBaseDao(); Connectionconn=null; PreparedStatementpstmt=null; publicintlogin(Stringusername,Stringpassword) { //管理员登录 conn=bs.getConnection(); ResultSetrs=null; intifmanager=3; Stringsql="Select*frommanagerwhereusername=? andpassword=? "; try { pstmt=conn.prepareStatement(sql); pstmt.setString(1,username); pstmt.setString(2,password); rs=pstmt.executeQuery(); if(rs.next()) { ifmanager=rs.getInt(4); System.out.println("登录成功"); System.out.println("----------------------"); } else System.out.println("登录失败,请校对用户名或者密码"); } catch(SQLExceptione) { e.printStackTrace(); } finally { bs.closeConn(conn,pstmt,rs); } returnifmanager; } jsp代码: Ui界面 <%@pagelanguage="java"contentType="text/html;charset=utf-8" pageEncoding="utf-8"%> DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http: //www.w3.org/TR/html4/loose.dtd">
账号 | |
密码 |
window.location.href='Out.jsp';">