package dao.impl;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import dao.ApplicantDao;
import pojo.Applicant;
import utils.C3P0Utils;
public class ApplicantDaoImpl implements ApplicantDao {
	private QueryRunner queryRunner = new QueryRunner(C3P0Utils.getDataSource());
	@Override
	//增加应聘人员
	public void saveApplicant(Applicant applicant) {
		/**
		 * 设置日期的格式
		 */
		SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		applicant.setCreatetime(Timestamp.valueOf(simpleDate.format(applicant.getCreatetime())));
		
		String sql ="insert into applicant(name,sex,age,job,specialty,experience,studyeffort,school,tel,email,createtime,content,isstock) values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
		Object[] params = new Object[]{applicant.getName(),applicant.getSex(),applicant.getAge(),applicant.getJob(),applicant.getSpecialty(),
				applicant.getExperience(),applicant.getStudyeffort(),applicant.getSchool(),applicant.getTel(),applicant.getEmail(),applicant.getCreatetime(),applicant.getContent()
				,applicant.getIsstock()};
		try {
			queryRunner.update(sql, params);
		} catch (SQLException e) {
			e.printStackTrace();
		}	
	}
	@Override
	public List findAllApplicants() {
		String sql ="select * from applicant";
		List<Applicant> list = null;
		try {
			 list = queryRunner.query(sql, new BeanListHandler<Applicant>(Applicant.class) );
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}
	@Override
	public Applicant findApplicantById(String id) {
		String sql ="select * from applicant where id = ?";
		Applicant applicant = null;
		try {
			applicant = queryRunner.query(sql,new BeanHandler<>(Applicant.class),id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return applicant;
	}
	@Override
	public void deleteApplicant(String id) {
		String sql ="delete from applicant where id =? ";
		try {
			queryRunner.update(sql, id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	@Override
	public void updateApplicant(String id) {
		String sql ="update applicant set isstock = 1 where id =? ";
		try {
			queryRunner.update(sql, id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	@Override
	public List findApplicantByIsstock(String isstock) {
		String sql ="select * from applicant where isstock = ?";
		List applicantList  = null;
		try {
			applicantList = queryRunner.query(sql,new BeanListHandler<>(Applicant.class),isstock);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return applicantList;
	}
}
最近下载更多
wttttts  LV2 2023年12月14日
dowell_liu  LV1 2023年8月2日
15236088421  LV2 2023年5月17日
jdzbvfuadk  LV2 2023年4月17日
qq2901732871  LV9 2023年4月6日
benbenyang  LV3 2023年3月14日
yunYUN123  LV1 2023年2月26日
java小书童  LV17 2023年2月23日
hjbobo6  LV3 2023年2月2日
jack567  LV2 2022年12月16日
最近浏览更多
educationAAA  LV4 4月23日
邓艺妮 4月3日
暂无贡献等级
zolscy  LV12 3月23日
暂无贡献等级
Boss绝  LV8 3月3日
暂无贡献等级
185838390  LV1 2月16日
阿卡丽  LV3 2月7日
werh0123  LV1 2月5日
gxxxxx 1月25日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友