package cn.st.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import cn.st.entity.Fill;
import cn.st.query.Page;
import cn.st.util.ConnDB;

public class FillDao {
   
	/**
	 * 导入 填空题
	 */
	public boolean addFill(Fill fill) {
    boolean bol=false;
		
		Connection conn=null;
		PreparedStatement ps=null;
		
		String sql="insert into tbl_fill(question,fill,answer,parse)"
				+ " values(?,?,?,?)";
		conn=ConnDB.getConnection();//获取数据库连接
		try {
			ps=conn.prepareStatement(sql);//预处理sql语句
			ps.setString(1, fill.getQuestion());//实体对象通过get方法获取值set到数据表中
			ps.setString(2, fill.getFill());
			ps.setString(3, fill.getAnswer());
			ps.setString(4, fill.getParse());
			ps.executeUpdate();
			bol=true;//数据添加成功后返回ture
			System.out.println("填空题题导入成功!!!");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				ps.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return bol;
	}
	
	/**
	 * 查看判断题
	 */
	public Page<Fill> queryAllFillIng(Page<Fill> page) {
		List<Fill> list=new ArrayList<Fill>();//实例化链表对象用于存取数据
		Fill fill=null;//声明实例化实体对象(判断题)
		Connection conn=null;
		PreparedStatement ps=null;
		ResultSet rs=null;
		StringBuffer sql =new StringBuffer("select * from tbl_fill  where 1=1");
		//分页限制
		if (page.getCurrentPage() == 1) {
			sql.append(" limit " + page.getPageSize());
       } else {
    	   sql.append(" limit " + (page.getCurrentPage()-1) * page.getPageSize() + "," + page.getPageSize() );

       }
		conn=ConnDB.getConnection();//获取数据库连接
		try {
			ps=conn.prepareStatement(sql.toString());
			rs=ps.executeQuery();
			while (rs.next()) {
				fill=new Fill();
				fill.setQuestion(rs.getString("question"));
				fill.setFill(rs.getString("fill"));
				fill.setAnswer(rs.getString("answer"));
				fill.setParse(rs.getString("parse"));
				list.add(fill);//将实体对象的值添加到链表对象中
				System.out.println("判断题数据查询成功"+fill.getQuestion());
			}
			page.setResult(list);//将链表的结果集分页
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				//关闭资源流
				rs.close();
				ps.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return page;
	}
	
	/**
	 * 统计选择题
	 */
	
	public long countFill() {
		long count=0;
		Connection conn=null;
		PreparedStatement ps=null;
		ResultSet rs=null;
		String sql="select count(*) as c from tbl_fill";
		
		conn=ConnDB.getConnection();//获取数据库连接
		try {
			ps=conn.prepareStatement(sql);//预处理sql语句
			rs=ps.executeQuery();
			while (rs.next()) {
				count=rs.getLong("c");
				
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			//关闭资源流
			try {
				rs.close();
				ps.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return count;
	}
}
最近下载更多
一脚踩在大腚上  LV7 2022年10月28日
wanglinddad  LV54 2022年5月22日
591231555  LV20 2022年4月18日
zhaoyangwfd  LV17 2022年3月31日
666666668  LV2 2022年2月26日
admin_z  LV22 2022年2月17日
fengqianqian  LV9 2021年12月15日
絮落无痕  LV13 2021年5月21日
wang512237140  LV20 2021年5月9日
didiaoD  LV4 2021年5月6日
最近浏览更多
2010160433  LV3 2023年11月30日
毫无语  LV6 2023年10月19日
blacklemon 2023年10月15日
暂无贡献等级
小妹妹  LV7 2023年10月10日
lpclpclpc  LV4 2023年9月20日
魏泽宇 2023年9月11日
暂无贡献等级
西瓜哥哥  LV4 2023年8月3日
暂无贡献等级
520131  LV5 2023年6月27日
LITIANYU084414  LV11 2023年6月16日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友