📄 gameassiimpl.java
字号:
/**
* (c) Copyright 2007 computer01
*
* FILENAME : GameAssiImpl.java
* PACKAGE : com.computer01.entitysuport
* CREATE DATE : 2007-12-28
* AUTHOR : admin
* DESCRIPTION :
*/
package com.computer01.entitysuport;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.computer01.common.Linkdb;
import com.computer01.entity.AllEntity;
import com.computer01.entity.TAB_CLASS;
import com.computer01.entity.TAB_GAMES;
import com.computer01.entity.TAB_STUDENTS;
public class GameAssiImpl extends TAB_GAMES
implements
EntityAssiInterface{
/**
* 数据库操作类
*/
Linkdb linkdb = null;
/**
* @author changruoting
*/
public void deleteEntity(AllEntity allentity) {
// TODO Auto-generated method stub
TAB_STUDENTS stu = allentity.getTabstudents();
try {
linkdb = new Linkdb();
StringBuffer buff = new StringBuffer();
buff.append("delete from " + "tab_students").append(
" where STUNO " + "='" + stu.getSTUNO() + "'");
linkdb.executeUpdate(buff.toString());
linkdb.closeStmt();
linkdb.closeConn();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 通过页码得到学生记录信息
*
* @param condition
* @param pageno
* 页码 第几页
* @param pernum
* 每页记录数
* @return 当前页面学生信息列表
*/
public List getStuEntityByPageno(AllEntity condition, int pageno, int pernum) {
List<AllEntity> allentlist = new ArrayList<AllEntity>();// 所有实体
List<AllEntity> pageentlist = new ArrayList<AllEntity>();// 当前页学生信息
allentlist = this.getEntityList(condition);
int allentlen = allentlist.size();
int pageStart = 0;// 开始记录数
pageStart = pernum * (pageno - 1);
for (int i = 0; i < pernum && i + pageStart < allentlen; i++) {
pageentlist.add(allentlist.get(pageStart + i));
}
return pageentlist;
}
public List getEntityList(AllEntity condition) {
// 学生实体信息列表
List<AllEntity> stuEntityList = new ArrayList<AllEntity>();
try {
linkdb = new Linkdb();
// sql Buffer
StringBuffer buff = new StringBuffer();
buff.append("select stu.STUNO,stu.STUNAME").append(
",stu.CLASSNO,cla.CLASSNAME,stu.PWD").append(
" from tab_students stu," + "tab_class cla").append(
" where stu.CLASSNO=cla.CLASSNO");
// 查询条件
TAB_STUDENTS stu = condition.getTabstudents();
if (stu != null) {
/** 按学号查询 */
if (stu.getSTUNO() != null && !"".equals(stu.getSTUNO())) {
buff.append(" " + "and stu.STUNO='" + stu.getSTUNO() + "'");
}
}
buff.append(" order by stu.STUNO ");
// 执行查询
ResultSet rs = linkdb.executeQuery(buff.toString());
while (rs.next()) {
// //封装
// 所有注册实体
AllEntity stuallentity = new AllEntity();
// 学生实体
TAB_STUDENTS stuentity = new TAB_STUDENTS();
stuentity.setSTUNO(rs.getString(1));
stuentity.setSTUNAME(rs.getString(2));
stuentity.setPWD(rs.getString(5));
// 设置班级实体信息
TAB_CLASS claentity = new TAB_CLASS();
claentity.setCLASSNO(new Integer(rs.getShort(3)));
claentity.setCLASSNAME(rs.getString(4));
// 设置学生实体中的班级实体信息
stuentity.setPK_TAB_CLASS(claentity);
// 把学生实体添加到allEntity
stuallentity.setTabstudents(stuentity);
// 将allEntity添加至list
stuEntityList.add(stuallentity);
}
} catch (Exception e) {
e.printStackTrace();
}
return stuEntityList;
}
public void saveEntity(AllEntity allentity) throws Exception {
// TODO Auto-generated method stub
// 学生信息`
TAB_STUDENTS stu = allentity.getTabstudents();
try {
// 数据库连接
linkdb = new Linkdb();
StringBuffer buff = new StringBuffer();
buff.append("insert into tab_students " + "values ('"
+ stu.getSTUNO() + "','" + stu.getSTUNAME() + "',"
+ stu.getPK_TAB_CLASS().getCLASSNO() + ")");
linkdb.executeUpdate(buff.toString());
linkdb.closeStmt();
linkdb.closeConn();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
/**
* 修改学生信息
*/
public int updateEntity(AllEntity allentity) {
try {
linkdb = new Linkdb();
TAB_STUDENTS stu = allentity.getTabstudents();
StringBuffer buff = new StringBuffer();
buff.append("UPDATE tab_students SET STUNAME='").append(
stu.getSTUNAME() + "',").append(" CLASSNO=").append(
stu.getPK_TAB_CLASS().getCLASSNO().intValue()).append(
" WHERE STUNO='" + stu.getSTUNO() + "';");
linkdb.executeUpdate(buff.toString());
linkdb.closeStmt();
linkdb.closeConn();
} catch (SQLException e) {
e.printStackTrace();
}
return 1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -