jobdao.java

来自「xueyuan gongzuojieshao」· Java 代码 · 共 294 行

JAVA
294
字号
/*
 * 创建日期 2007-5-1
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
package dao.login;

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 oracle.DBConnection;
import bean.job.jobBean;

/**
 * @author Administrator
 *
 * TODO 要更改此生成的类型注释的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
public class jobDao {
	
	//根据输入的信息向JOB表里插入数据
	
	public int insertJob(jobBean bean){
		int ret = 0;
		String sql = " insert into job values(job_seq.nextval,?,?,?,?,?,?,?,?,?,?,sysdate,?,0)";
		Connection conn = null;
		PreparedStatement stm = null;
		try {
			conn = DBConnection.getConnection();
			conn.setAutoCommit(false);
			stm = conn.prepareStatement(sql);
			stm.setString(1,bean.getJob_Name());
			stm.setString(2,bean.getJob_Sex());
			stm.setString(3,bean.getJob_Age());
			stm.setString(4,bean.getJob_Job());
			stm.setString(5,bean.getJob_Specialty());
		    stm.setString(6,bean.getJob_experience());
			stm.setString(7,bean.getJob_StudyEffort());
			stm.setString(8,bean.getJob_Shool());
			stm.setString(9,bean.getJob_Tel());
			stm.setString(10,bean.getJob_Email());
			stm.setString(11,bean.getJob_Content());
			stm.executeUpdate();
			conn.commit();
			ret = 1;
			
		} catch (SQLException e) {
			try {
				conn.rollback();
			} catch (SQLException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}finally{
			try {
				conn.setAutoCommit(true);
				stm.close();
				conn.close();
			} catch (SQLException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}
		}
		return ret;
	}
	
	//查询招聘信息
	
	public List selectJob(){
		
		List list = new ArrayList();
		String sql = " select * from job where job_Isstock=0";
		Connection conn = null;
		PreparedStatement stm = null;
		ResultSet rs = null;
		
		try {
			conn = DBConnection.getConnection();
			stm = conn.prepareStatement(sql);
			rs = stm.executeQuery();
			while(rs.next()){
				jobBean bean = new jobBean();
				bean.setJob_id(rs.getString("job_id"));
				bean.setJob_Name(rs.getString("job_Name"));
				if(rs.getInt("job_Sex")==1){
					bean.setJob_Sex("男");
				}else{
					bean.setJob_Sex("女");
				}
				bean.setJob_Age(rs.getString("job_Age"));
				bean.setJob_Job(rs.getString("job_Job"));
				bean.setJob_Specialty(rs.getString("job_Specialty"));
				bean.setJob_experience(rs.getString("job_experience"));
				bean.setJob_StudyEffort(rs.getString("job_StudyEffort"));
				list.add(bean);
			}
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}finally{
			try {
				rs.close();
				stm.close();
				conn.close();
			} catch (SQLException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}
		}
		return list;
		
	}
	
	//根据job_id查询详细信息
	
	public jobBean selectPersonAll(jobBean bean){
	    String sql =" select * from job where job_id="+bean.getJob_id();
	    Connection conn = null;
		PreparedStatement stm = null;
		ResultSet rs = null;
		try {
			conn = DBConnection.getConnection();
			stm = conn.prepareStatement(sql);
			rs = stm.executeQuery();
			while(rs.next()){
				bean.setJob_Name(rs.getString("job_Name"));
				if(rs.getInt("job_Sex")==1){
					bean.setJob_Sex("男");
				}else{
					bean.setJob_Sex("女");
				}
				bean.setJob_Age(rs.getString("job_Age"));
				bean.setJob_Job(rs.getString("job_Job"));
				bean.setJob_Specialty(rs.getString("job_Specialty"));
				bean.setJob_experience(rs.getString("job_experience"));
				bean.setJob_StudyEffort(rs.getString("job_StudyEffort"));
				bean.setJob_Shool(rs.getString("job_Shool"));
				bean.setJob_Tel(rs.getString("job_Tel"));
				bean.setJob_Email(rs.getString("job_Email"));
				bean.setJob_Content(rs.getString("job_Content"));
			}
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}finally{
			try {
				rs.close();
				stm.close();
				conn.close();
			} catch (SQLException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}
		}
		
		
		return bean;
	}
	
	//根据提供的job_id进行入库操作
	
	public int selectInsert(jobBean bean){
		int ret = 0;
		String sql = " update job set job_Isstock=1 where job_id="+bean.getJob_id();
		Connection conn = null;
		PreparedStatement stm = null;
		
		try {
			conn = DBConnection.getConnection(); 
			stm = conn.prepareStatement(sql);
			ret = stm.executeUpdate();
		} catch (SQLException e) {
			try {
				conn.rollback();
			} catch (SQLException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}finally{
			try {
				stm.close();
				conn.close();
			} catch (SQLException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}
		}
		return ret;
	}
	
	//根据job_id删除相关记录
	
	public int selectDrop(jobBean bean){
		int ret = 0;
		String sql = " delete from job where job_id ="+bean.getJob_id();
		Connection conn =null;
		PreparedStatement stm = null;
		try {
			conn = DBConnection.getConnection();
			stm = conn.prepareStatement(sql);
			ret = stm.executeUpdate();
		} catch (SQLException e) {
			try {
				conn.rollback();
			} catch (SQLException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}finally{
			try {
				stm.close();
				conn.close();
			} catch (SQLException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}
		}
		return ret;
	}
	
	//查询人才
	
	public List select(){
		List list = new ArrayList();
		String sql =" select * from job where job_Isstock=1";
		Connection conn = null;
		PreparedStatement stm =null;
		ResultSet rs = null;
		
		try {
			conn = DBConnection.getConnection();
			stm =conn.prepareStatement(sql);
			rs = stm.executeQuery();
			while(rs.next()){
				jobBean bean = new jobBean();
				bean.setJob_id(rs.getString("job_id"));
				bean.setJob_Name(rs.getString("job_Name"));
				if(rs.getInt("job_Sex")==1){
					bean.setJob_Sex("男");
				}else{
					bean.setJob_Sex("女");
				}
				bean.setJob_Age(rs.getString("job_Age"));
				bean.setJob_Job(rs.getString("job_Job"));
				bean.setJob_Specialty(rs.getString("job_Specialty"));
				bean.setJob_experience(rs.getString("job_experience"));
				bean.setJob_StudyEffort(rs.getString("job_StudyEffort"));
				list.add(bean);
			}
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}finally{
			try {
				rs.close();
				stm.close();
				conn.close();
			} catch (SQLException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}
		}
		return list;
	}

}















⌨️ 快捷键说明

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