《学生信息管理系统》详细设计说明书
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
importjava.util.ArrayList;
System.out.println("执行多个SQL语句失败,错误信息是:"+ e.getMessage());
try{
conn.close();
}catch(SQLException e1) {
}
}
}
returnresult;
}
//生成与数据库的连接
privatestaticvoidgetconnection() {
String sql ="select * from student";
ResultSet rs = DbService.executeSelect(sql);
try{
while(rs.next()) {
Student student =newStudent();
student.setXh(rs.getString("xh"));
privateStringxh;
privateStringxm;
privateStringxb;
privateStringzy;
privateintnl;
publicString getXh() {
returnxh;
}
publicvoidsetXh(String xh) {
this.xh= xh;
}
Student student =newStudent();
try{
rs.next();
if(null!= rs) {
student.setXh(xh);
student.setXm(rs.getString("xm"));
student.setXb(rs.getString("xb"));
student.setZy(rs.getString("zy"));
intresult = -1;
if(null==conn) {
DbService.getconnection();
}
if(null!=conn) {
try{
Statement stm =conn.createStatement();
conn.setAutoCommit(false);
for(intii = 0; ii < sqlArraylist.size(); ii++) {
sql = sql +"nl="+ student.getNl();
sql = sql +" where xh='"+ student.getXh() +"'";
returnDbService.executeUpdate(sql);
}
publicintdel(Student student) {
String sql ="delete from student where xh='"+ student.getXh() +"'";
returnzy;
}
publicvoidsetZy(String zy) {
this.zy= zy;
}
publicintgetNl() {
returnnl;
}
publicvoidsetNl(intnl) {
this.nl= nl;
}
}
五、建立“学生”对象的Dao数据操作处理
1、建立Dao的接口StudentDao
结束并生成代码:StudentDaoຫໍສະໝຸດ Baidu
packagecom.student.dao;
importjava.util.ArrayList;
importcom.student.model.Student;
publicinterfaceStudentDao {
publicintsave(Student student);
publicString getXm() {
returnxm;
}
publicvoidsetXm(String xm) {
this.xm= xm;
}
publicString getXb() {
returnxb;
}
publicvoidsetXb(String xb) {
this.xb= xb;
}
publicString getZy() {
student.setNl(rs.getInt("nl"));
}
}catch(SQLException e) {
System.out.println(e.getMessage());
}
returnstudent;
}
publicArrayList<Student> getlist() {
ArrayList<Student> ar =newArrayList<Student>();
System.out.println("执行SQL语句失败!错误信息是:"+ e.getMessage());
}
}
returnresult;
}
//执行查询SQL语句
publicstaticResultSet executeSelect(String sql) {
ResultSet rSet =null;
stm.addBatch(sqlArraylist.get(ii));
}
int[] rs = stm.executeBatch();
if(null== rs) {
conn.rollback();
}else{
conn.commit();
result = 1;
}
}catch(SQLException e) {
returnDbService.executeUpdate(sql);
}
publicStudent getone(String xh) {
String sql ="select * from student where xh='"+ xh +"'";
ResultSet rs = DbService.executeSelect(sql);
importcom.db.DbService;
importcom.student.dao.StudentDao;
importcom.student.model.Student;
publicclassStudentDaoImplimplementsStudentDao {
publicintsave(Student student) {
publicintmodify(Student student);
publicintdel(Student student);
publicStudent getone(String xh);
publicArrayList<Student> getlist();
publicArrayList<Student> getlist(String where);
}catch(SQLException e) {
System.out.println(e.getMessage());
}
returnar;
}
publicArrayList<Student> getlist(String where) {
ArrayList<Student> ar =newArrayList<Student>();
《学生信息管理系统》实验指导
一、创建Web Project工程
1、选择创建web project工程
2、创建后的界面图示
3、发布的tomcat服务器
二、建立与数据库连接的java类:DbService
在src下创建类DbService:
结束后并构建DbService如下:
packagecom.db;
System.out.println("数据库连接错误,错误信息!"+e.getMessage());
}
}
}
三、建立数据库表student
四、建立“学生”对象的数据模型
在myeclipse中创建类Student
结束后并生成代码如下:Student类
packagecom.student.model;
publicclassStudent {
sql = sql +"'"+ student.getZy() +"',";
sql = sql + student.getNl() +")";
returnDbService.executeUpdate(sql);
}
publicintmodify(Student student) {
String sql ="update student set ";
System.out.println("执行SQL语句失败!错误信息是:"+ e.getMessage());
}
}
returnrSet;
}
//执行多个SQL语句,以事务的方式进行
publicstaticintexecuteTrans(ArrayList<String> sqlArraylist) {
student.setXm(rs.getString("xm"));
student.setXb(rs.getString("xb"));
student.setZy(rs.getString("zy"));
student.setNl(rs.getInt("nl"));
ar.add(student);
}
intresult = -1;
if(null==conn) {
DbService.getconnection();
}
if(null!=conn) {
try{
Statement stm =conn.createStatement();
result = stm.executeUpdate(sql);
}catch(SQLException e) {
try{
Class.forName(DRIVE);
}catch(ClassNotFoundException e) {
System.out.println("没有找到驱动程序!");
}
try{
conn= DriverManager.getConnection(URL,USER,PASS);
}catch(SQLException e) {
}
2、生成StudentDao的实现类:StudentDaoImpl
结束并生成代码如下:StudentDaoImpl类:
packagecom.student.dao.impl;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.util.ArrayList;
String sql ="insert into student(xh,xm,xb,zy,nl) values(";
sql = sql +"'"+ student.getXh() +"',";
sql = sql +"'"+ student.getXm() +"',";
sql = sql +"'"+ student.getXb() +"',";
if(null==conn) {
DbService.getconnection();
}
if(null!=conn) {
try{
Statement stm =conn.createStatement();
rSet = stm.executeQuery(sql);
}catch(SQLException e) {
privatestaticfinalStringUSER="sa";//数据库用户名
privatestaticfinalStringPASS="sun910309";//用户密码
privatestaticConnectionconn=null;
//执行inser update delete语句
publicstaticintexecuteUpdate(String sql) {
publicclassDbService {
privatestaticfinalStringURL="jdbc:sqlserver://localhost:1433;databaseName=studyDatabase";
privatestaticfinalStringDRIVE="com.microsoft.sqlserver.jdbc.SQLServerDriver";
sql = sql +"xh='"+ student.getXh() +"',";
sql = sql +"xm='"+ student.getXm() +"',";
sql = sql +"xb='"+ student.getXb() +"',";
sql = sql +"zy='"+ student.getZy() +"',";
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
importjava.util.ArrayList;
System.out.println("执行多个SQL语句失败,错误信息是:"+ e.getMessage());
try{
conn.close();
}catch(SQLException e1) {
}
}
}
returnresult;
}
//生成与数据库的连接
privatestaticvoidgetconnection() {
String sql ="select * from student";
ResultSet rs = DbService.executeSelect(sql);
try{
while(rs.next()) {
Student student =newStudent();
student.setXh(rs.getString("xh"));
privateStringxh;
privateStringxm;
privateStringxb;
privateStringzy;
privateintnl;
publicString getXh() {
returnxh;
}
publicvoidsetXh(String xh) {
this.xh= xh;
}
Student student =newStudent();
try{
rs.next();
if(null!= rs) {
student.setXh(xh);
student.setXm(rs.getString("xm"));
student.setXb(rs.getString("xb"));
student.setZy(rs.getString("zy"));
intresult = -1;
if(null==conn) {
DbService.getconnection();
}
if(null!=conn) {
try{
Statement stm =conn.createStatement();
conn.setAutoCommit(false);
for(intii = 0; ii < sqlArraylist.size(); ii++) {
sql = sql +"nl="+ student.getNl();
sql = sql +" where xh='"+ student.getXh() +"'";
returnDbService.executeUpdate(sql);
}
publicintdel(Student student) {
String sql ="delete from student where xh='"+ student.getXh() +"'";
returnzy;
}
publicvoidsetZy(String zy) {
this.zy= zy;
}
publicintgetNl() {
returnnl;
}
publicvoidsetNl(intnl) {
this.nl= nl;
}
}
五、建立“学生”对象的Dao数据操作处理
1、建立Dao的接口StudentDao
结束并生成代码:StudentDaoຫໍສະໝຸດ Baidu
packagecom.student.dao;
importjava.util.ArrayList;
importcom.student.model.Student;
publicinterfaceStudentDao {
publicintsave(Student student);
publicString getXm() {
returnxm;
}
publicvoidsetXm(String xm) {
this.xm= xm;
}
publicString getXb() {
returnxb;
}
publicvoidsetXb(String xb) {
this.xb= xb;
}
publicString getZy() {
student.setNl(rs.getInt("nl"));
}
}catch(SQLException e) {
System.out.println(e.getMessage());
}
returnstudent;
}
publicArrayList<Student> getlist() {
ArrayList<Student> ar =newArrayList<Student>();
System.out.println("执行SQL语句失败!错误信息是:"+ e.getMessage());
}
}
returnresult;
}
//执行查询SQL语句
publicstaticResultSet executeSelect(String sql) {
ResultSet rSet =null;
stm.addBatch(sqlArraylist.get(ii));
}
int[] rs = stm.executeBatch();
if(null== rs) {
conn.rollback();
}else{
conn.commit();
result = 1;
}
}catch(SQLException e) {
returnDbService.executeUpdate(sql);
}
publicStudent getone(String xh) {
String sql ="select * from student where xh='"+ xh +"'";
ResultSet rs = DbService.executeSelect(sql);
importcom.db.DbService;
importcom.student.dao.StudentDao;
importcom.student.model.Student;
publicclassStudentDaoImplimplementsStudentDao {
publicintsave(Student student) {
publicintmodify(Student student);
publicintdel(Student student);
publicStudent getone(String xh);
publicArrayList<Student> getlist();
publicArrayList<Student> getlist(String where);
}catch(SQLException e) {
System.out.println(e.getMessage());
}
returnar;
}
publicArrayList<Student> getlist(String where) {
ArrayList<Student> ar =newArrayList<Student>();
《学生信息管理系统》实验指导
一、创建Web Project工程
1、选择创建web project工程
2、创建后的界面图示
3、发布的tomcat服务器
二、建立与数据库连接的java类:DbService
在src下创建类DbService:
结束后并构建DbService如下:
packagecom.db;
System.out.println("数据库连接错误,错误信息!"+e.getMessage());
}
}
}
三、建立数据库表student
四、建立“学生”对象的数据模型
在myeclipse中创建类Student
结束后并生成代码如下:Student类
packagecom.student.model;
publicclassStudent {
sql = sql +"'"+ student.getZy() +"',";
sql = sql + student.getNl() +")";
returnDbService.executeUpdate(sql);
}
publicintmodify(Student student) {
String sql ="update student set ";
System.out.println("执行SQL语句失败!错误信息是:"+ e.getMessage());
}
}
returnrSet;
}
//执行多个SQL语句,以事务的方式进行
publicstaticintexecuteTrans(ArrayList<String> sqlArraylist) {
student.setXm(rs.getString("xm"));
student.setXb(rs.getString("xb"));
student.setZy(rs.getString("zy"));
student.setNl(rs.getInt("nl"));
ar.add(student);
}
intresult = -1;
if(null==conn) {
DbService.getconnection();
}
if(null!=conn) {
try{
Statement stm =conn.createStatement();
result = stm.executeUpdate(sql);
}catch(SQLException e) {
try{
Class.forName(DRIVE);
}catch(ClassNotFoundException e) {
System.out.println("没有找到驱动程序!");
}
try{
conn= DriverManager.getConnection(URL,USER,PASS);
}catch(SQLException e) {
}
2、生成StudentDao的实现类:StudentDaoImpl
结束并生成代码如下:StudentDaoImpl类:
packagecom.student.dao.impl;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.util.ArrayList;
String sql ="insert into student(xh,xm,xb,zy,nl) values(";
sql = sql +"'"+ student.getXh() +"',";
sql = sql +"'"+ student.getXm() +"',";
sql = sql +"'"+ student.getXb() +"',";
if(null==conn) {
DbService.getconnection();
}
if(null!=conn) {
try{
Statement stm =conn.createStatement();
rSet = stm.executeQuery(sql);
}catch(SQLException e) {
privatestaticfinalStringUSER="sa";//数据库用户名
privatestaticfinalStringPASS="sun910309";//用户密码
privatestaticConnectionconn=null;
//执行inser update delete语句
publicstaticintexecuteUpdate(String sql) {
publicclassDbService {
privatestaticfinalStringURL="jdbc:sqlserver://localhost:1433;databaseName=studyDatabase";
privatestaticfinalStringDRIVE="com.microsoft.sqlserver.jdbc.SQLServerDriver";
sql = sql +"xh='"+ student.getXh() +"',";
sql = sql +"xm='"+ student.getXm() +"',";
sql = sql +"xb='"+ student.getXb() +"',";
sql = sql +"zy='"+ student.getZy() +"',";