subject_studentdao.java

来自「可以实现在线考试」· Java 代码 · 共 79 行

JAVA
79
字号
package business;

import java.sql.*;
import java.util.ArrayList;

import po.RelationPO;

public class Subject_StudentDAO 
{
	private Connection conn = null;
	private Statement state = null;
	private ResultSet rs = null;
	
	//查询出与些学号对应的全部科目
	public ArrayList findByRelationSid(int sid)
	{
		ArrayList array = new ArrayList();
		conn = dao.Tools.getConnection();
		try {
			state = conn.createStatement();
			rs = state.executeQuery("select * from relation where sid ="+sid);
			while(rs.next())
			{
				RelationPO rpo = new RelationPO();
				rpo.setCid(rs.getInt("cid"));
				rpo.setSid(rs.getInt("sid"));
				rpo.setGid(rs.getInt("gid"));
				rpo.setExamflag(rs.getString("examflag"));
				array.add(rpo);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if(rs != null)
				rs.close();
				if(state != null)
				state.close();
				if(conn != null)
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return array;
	}
	
	//修改该科目的考试状态
	public boolean modifyByRelationSid(int sid,int cid)
	{
		boolean isok = false;
		conn = dao.Tools.getConnection();
		try {
			state = conn.createStatement();
			int i = state.executeUpdate("update relation set examflag = 'YES' where sid = "+sid +"and cid ="+cid);
			if(i > 0)
			{
				isok = true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if(state != null)
				state.close();
				if(conn != null)
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return isok;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?