📄 examineedao.java
字号:
package edu.yinhe.mis.model;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import edu.yinhe.mis.dto.CheckInfoDTO;
import edu.yinhe.mis.dto.ExamineeDTO;
import edu.yinhe.mis.vo.CheckInfoVO;
import edu.yinhe.mis.vo.ExamineeVO;
import edu.yinhe.mis.vo.QuestionVO;
import edu.yinhe.mis.vo.TestPaperVO;
import edu.yinhe.mis.vo.TestpaperruleVO;
import edu.yinhe.system.model.BaseDAO;
/**
* 此类用于对examinee表的基本操作
* @author 刘洲
* 2008-04-30
*/
public class ExamineeDAO extends BaseDAO{
/**
* 根据考号删除考生信息
* @param 考号
* @return boolean
* @throws SQLException
*/
public Object delete(Object obj) throws SQLException {
boolean isTrue=false;
String SQL="";
Integer exam_id=null;
PreparedStatement ps=null;
try {
exam_id=(Integer)obj;
SQL="DELETE FROM examinee WHERE id="+exam_id;
ps=conn.prepareStatement(SQL);
ps.executeUpdate();
isTrue=true;
} finally{
if(ps!=null)ps.close();
SQL=null;
exam_id=null;
}
return isTrue;
}
/**
* 查询考试科目
* @return 考试科目
* @throws SQLException
*/
public Object find() throws SQLException {
ArrayList alist=null;
CheckInfoVO checkInfoVO=null;
CheckInfoDTO checkInfoDTO=null;
PreparedStatement ps=null;
ResultSet rs=null;
String SQL="";
try {
SQL="SELECT DISTINCT object_name FROM check_info_table";
ps=conn.prepareStatement(SQL);
rs=ps.executeQuery();
alist=new ArrayList();
while(rs.next()){
checkInfoVO=new CheckInfoVO();
checkInfoVO.setObject_name(rs.getString("object_name"));
alist.add(checkInfoVO);
}
} finally{
if(ps!=null)ps.close();
if(rs!=null)rs.close();
checkInfoVO=null;
SQL=null;
}
return alist;
}
/**
* D查询考场信息
* @param CheckInfoDTO
* @return 考场相关信息
* @throws SQLException
*/
public Object find(Object obj) throws SQLException {
ArrayList alist=null;
CheckInfoVO checkInfoVO=null;
CheckInfoDTO checkInfoDTO=null;
PreparedStatement ps=null;
ResultSet rs=null;
String SQL="";
try {
checkInfoDTO=(CheckInfoDTO)obj;
StringBuffer sb=new StringBuffer("SELECT object_name,check_id FROM check_info_table WHERE 1=1 ");
if(checkInfoDTO.getObject_name()!=null&&!"".equals(checkInfoDTO.getObject_name())){
sb.append("AND object_name='"+checkInfoDTO.getObject_name()+"'");
}
SQL=sb.toString();
ps=conn.prepareStatement(SQL);
rs=ps.executeQuery();
alist=new ArrayList();
while(rs.next()){
checkInfoVO=new CheckInfoVO();
checkInfoVO.setObject_name(rs.getString("object_name"));
checkInfoVO.setCheck_id(rs.getInt("check_id"));
alist.add(checkInfoVO);
}
} finally{
if(ps!=null)ps.close();
if(rs!=null)rs.close();
checkInfoVO=null;
SQL=null;
}
return alist;
}
public Object findAll() throws SQLException {
return null;
}
/**
* 查询考生信息
* @param ExamineeDTO
* @return 考生相关信息
* @throws SQLException
*/
public Object findAll(Object obj) throws SQLException {
ExamineeDTO examineeDTO=null;
ExamineeVO examineeVO=null;
ArrayList alist=null;
Object[] object=null;
PreparedStatement ps=null;
ResultSet rs=null;
String SQL="";
Integer count=0;
try {
count=getCount(obj);
examineeDTO=(ExamineeDTO)obj;
StringBuffer sb=new StringBuffer("SELECT ID,NAME,EXAM_NO,PASSWORD,CHECK_ID,OBJECT_NAME,STATE,FETLE FROM examinee WHERE 1=1 ");
if(examineeDTO.getName()!=null&&!"".equals(examineeDTO.getName())){
sb.append("AND name LIKE '%"+examineeDTO.getName()+"%' ");
}
if(examineeDTO.getExam_NO()!=null&&!"".equals(examineeDTO.getExam_NO())){
sb.append("AND exam_no LIKE '%"+examineeDTO.getExam_NO()+"%'");
}
if(examineeDTO.getPassword()!=null&&!"".equals(examineeDTO.getPassword())){
sb.append("AND password='"+examineeDTO.getPassword()+"'");
}
if(examineeDTO.getObject_name()!=null&&!"".equals(examineeDTO.getObject_name())){
sb.append("AND object_name='"+examineeDTO.getObject_name()+"'");
}
if(examineeDTO.getCheck_ID()!=null&&examineeDTO.getCheck_ID()!=0){
sb.append("AND check_id="+examineeDTO.getCheck_ID());
}
if(examineeDTO.getID()!=null&&examineeDTO.getID()!=0){
sb.append("AND id="+examineeDTO.getID());
}
if(examineeDTO.getCurrentPage()!=null&&!"".equals(examineeDTO.getCurrentPage())&&examineeDTO.getRowPerPage()!=null&&!"".equals(examineeDTO.getRowPerPage())){
int currentRow=(Integer.parseInt(examineeDTO.getCurrentPage())-1)*Integer.parseInt(examineeDTO.getRowPerPage());
sb.append(" LIMIT "+currentRow+","+Integer.parseInt(examineeDTO.getRowPerPage()));
}
SQL=sb.toString();
ps=conn.prepareStatement(SQL);
rs=ps.executeQuery();
alist=new ArrayList();
while(rs.next()){
examineeVO=new ExamineeVO();
examineeVO.setID(rs.getInt("id"));
examineeVO.setName(rs.getString("name"));
examineeVO.setExam_NO(rs.getString("exam_no"));
examineeVO.setPassword(rs.getString("password"));
examineeVO.setCheck_ID(rs.getInt("check_id"));
examineeVO.setObject_name(rs.getString("object_name"));
examineeVO.setState(rs.getInt("state"));
alist.add(examineeVO);
}
object=new Object[2];
object[0]=count;
object[1]=alist;
}finally{
}
return object;
}
/**
* 王小龙使用(根据试卷名称看是否能得到试卷对象)
*/
public Object findById(Object arg0) throws SQLException {
PreparedStatement ps=null;
ResultSet rs=null;
String SQL="";
String flag = "false";
String paperName = (String) arg0;
SQL = "SELECT * FROM testpaper WHERE TESTPAPER_NAME=?";
try {
ps = conn.prepareStatement(SQL);
ps.setString(1, paperName);
rs = ps.executeQuery();
if(rs.next()){
flag = "true";
}
} catch (RuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(rs!=null)rs=null;
if(ps!=null)ps=null;
SQL=null;
}
return flag;
}
/**
* 王小龙使用 (根据试卷规则得到试题)
*/
public Object findByObject(Object arg0) throws SQLException {
PreparedStatement ps=null;
ResultSet rs=null;
String SQL="";
TestpaperruleVO ruleVO = null;
QuestionVO questionVO = null;
ArrayList rulelist = (ArrayList) arg0;
ArrayList questionlist = new ArrayList();
try {
for(Iterator it=rulelist.iterator();it.hasNext();){
ruleVO = (TestpaperruleVO) it.next();
SQL = "SELECT QUESTION_ID,QUESTIONTYPE_ID,OBJECT_NAME FROM question WHERE QUESTIONTYPE_ID=? " +
" AND OBJECT_NAME=? ORDER BY rand() LIMIT 0,?";
ps = conn.prepareStatement(SQL);
ps.setInt(1, ruleVO.getQuestionTypeID());
ps.setString(2, ruleVO.getObjectName());
ps.setInt(3, ruleVO.getQuestionAmount());
rs = ps.executeQuery();
while(rs.next()){
questionVO = new QuestionVO();
questionVO.setQuestionID(rs.getInt("QUESTION_ID"));
questionVO.setQuestionTypeID(rs.getInt("QUESTIONTYPE_ID"));
questionVO.setObjectName(rs.getString("OBJECT_NAME"));
questionlist.add(questionVO);
}
}
} catch (RuntimeException e) {
e.printStackTrace();
}finally{
if(rs!=null)rs=null;
if(ps!=null)ps=null;
SQL=null;
ruleVO = null;
questionVO = null;
rulelist = null;
}
return questionlist;
}
/**
* 得到examinee表中记录总行数
* @param ExamineeDTO
* @return int
* @exception SQLException
*/
public int getCount(Object obj) throws SQLException {
Integer acount =new Integer(0);
ExamineeDTO examineeDTO=null;
PreparedStatement ps=null;
ResultSet rs=null;
String SQL=null;
try {
examineeDTO=(ExamineeDTO)obj;
StringBuffer sb=new StringBuffer("SELECT COUNT(*) FROM examinee WHERE 1=1");
if(examineeDTO.getName()!=null&&!"".equals(examineeDTO.getName())){
sb.append(" AND name LIKE '%"+examineeDTO.getName()+"%'");
}
if(examineeDTO.getCheck_ID()!=null&&examineeDTO.getCheck_ID()!=0){
sb.append(" AND check_id="+examineeDTO.getCheck_ID());
}
if(examineeDTO.getObject_name()!=null&&!"".equals(examineeDTO.getObject_name())){
sb.append(" AND object_name='"+examineeDTO.getObject_name()+"'");
}
if(examineeDTO.getExam_NO()!=null&&!"".equals(examineeDTO.getExam_NO())){
sb.append(" AND exam_no LIKE '%"+examineeDTO.getExam_NO()+"%'");
}
SQL=sb.toString();
ps=conn.prepareStatement(SQL);
rs=ps.executeQuery();
while(rs.next()){
acount=rs.getInt(1);
}
}finally{
if(rs!=null)rs=null;
if(ps!=null)ps=null;
SQL=null;
}
return acount;
}
public Object getMaxId(Object arg0) throws SQLException {
return null;
}
/**
* 在examinee表中插入记录
* @param ExamineeDTO
* @return boolean
* @exception SQLException
*/
public Object insert(Object obj) throws SQLException {
boolean isTrue=false;
ExamineeDTO examineeDTO=null;
PreparedStatement ps=null;
ResultSet rs=null;
String SQL="";
int index=1;
try {
examineeDTO=(ExamineeDTO)obj;
SQL="INSERT INTO examinee(name,exam_no,password,check_id,object_name) VALUES(?,?,?,?,?)";
ps=conn.prepareStatement(SQL);
ps.setString(index++, examineeDTO.getName());
ps.setString(index++, examineeDTO.getExam_NO());
ps.setString(index++, examineeDTO.getPassword());
ps.setInt(index++, examineeDTO.getCheck_ID());
ps.setString(index++, examineeDTO.getObject_name());
ps.executeUpdate();
isTrue=true;
}finally{
if(ps!=null)ps.close();
if(rs!=null)rs.close();
examineeDTO=null;
SQL=null;
}
return isTrue;
}
/**
* 修改考生信息
* @param ExamineeDTO
* @return boolean
* @exception SQLException
*/
public Object update(Object obj) throws SQLException {
boolean isTrue=false;
ExamineeDTO examineeDTO=null;
PreparedStatement ps=null;
ResultSet rs=null;
String SQL="";
int index=1;
try {
examineeDTO=(ExamineeDTO)obj;
SQL="UPDATE examinee SET check_id=?,object_name=? WHERE ID=?";
ps=conn.prepareStatement(SQL);
ps.setInt(index++, examineeDTO.getCheck_ID());
ps.setString(index++, examineeDTO.getObject_name());
ps.setInt(index++, examineeDTO.getID());
ps.executeUpdate();
isTrue=true;
}finally{
if(ps!=null)ps.close();
if(rs!=null)rs.close();
examineeDTO=null;
SQL=null;
}
return isTrue;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -