当前位置:文档之家› 《学生信息管理系统》详细设计说明书

《学生信息管理系统》详细设计说明书

publicString getXm() {
returnxm;
}
publicvoidsetXm(String xm) {
this.xm= xm;
}
publicString getXb() {
returnxb;
}
publicvoidsetXb(String xb) {
this.xb= xb;
}
publicString getZy() {
privatestaticfinalStringUSER="sa";//数据库用户名
privatestaticfinalStringPASS="sun910309";//用户密码
privatestaticConnectionconn=null;
//执行inser update delete语句
publicstaticintexecuteUpdate(String sql) {
returnzy;
}
publicvoidsetZy(String zy) {
this.zy= zy;
}
publicintgetNl() {
returnnl;
}
publicvoidsetNl(intnl) {
this.nl= nl;
}
}
五、建立“学生”对象的Dao数据操作处理
1、建立Dao的接口StudentDao
privateStringxh;
privateStringxm;
privateStringxb;
privateStringzy;
privateintnl;
publicString getXh() {
returnxh;
}
publicvoidsetXh(String xh) {
this.xh= xh;
}
}
2、生成StudentDao的实现类:StudentDaoImpl
结束并生成代码如下:StudentDaoImpl类:
packagecom.student.dao.impl;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.util.ArrayList;
System.out.println("执行多个SQL语句失败,错误信息是:"+ e.getMessage());
try{
conn.close();
}catch(SQLException e1) {
}
}
}
returnresult;
}
//生成与数据库的连接
privatestaticvoidgetconnection() {
intresult = -1;
if(null==conn) {
DbService.getconnection();
}
if(null!=conn) {
try{
Statement stm =conn.createStatement();
result = stm.executeUpdate(sql);
}catch(SQLException e) {
stm.addBatch(sqlArraylist.get(ii));
}
int[] rs = stm.executeBatch();
if(null== rs) {
conn.rollback();
}else{
mit();
result = 1;
}
}catch(SQLException e) {
System.out.println("执行SQL语句失败!错误信息是:"+ e.getMessage());
}
}
returnresult;
}
//执行查询SQL语句
publicstaticResultSet executeSelect(String sql) {
ResultSet rSet =null;
sql = sql +"xh='"+ student.getXh() +"',";
sql = sql +"xm='"+ student.getXm() +"',";
sql = sql +"xb='"+ student.getXb() +"',";
sql = sql +"zy='"+ student.getZy() +"',";
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() +"'";
System.out.println("执行SQL语句失败!错误信息是:"+ e.getMessage());
}
}
retห้องสมุดไป่ตู้rnrSet;
}
//执行多个SQL语句,以事务的方式进行
publicstaticintexecuteTrans(ArrayList<String> sqlArraylist) {
}catch(SQLException e) {
System.out.println(e.getMessage());
}
returnar;
}
publicArrayList<Student> getlist(String where) {
ArrayList<Student> ar =newArrayList<Student>();
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"));
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
importjava.util.ArrayList;
publicclassDbService {
privatestaticfinalStringURL="jdbc:sqlserver://localhost:1433;databaseName=studyDatabase";
privatestaticfinalStringDRIVE="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String sql ="insert into student(xh,xm,xb,zy,nl) values(";
sql = sql +"'"+ student.getXh() +"',";
sql = sql +"'"+ student.getXm() +"',";
sql = sql +"'"+ student.getXb() +"',";
System.out.println("数据库连接错误,错误信息!"+e.getMessage());
}
}
}
三、建立数据库表student
四、建立“学生”对象的数据模型
在myeclipse中创建类Student
结束后并生成代码如下:Student类
packagecom.student.model;
publicclassStudent {
student.setXm(rs.getString("xm"));
student.setXb(rs.getString("xb"));
student.setZy(rs.getString("zy"));
student.setNl(rs.getInt("nl"));
ar.add(student);
}
sql = sql +"'"+ student.getZy() +"',";
sql = sql + student.getNl() +")";
相关主题