⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stipenddao.java

📁 07年做得人力资源管理系统
💻 JAVA
字号:
package com.buat.hr.stipend;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;
import com.buat.hr.share.DBConnection;
import java.sql.Date;


public class StipendDAO implements IStipendDAO{
	DBConnection connection=new DBConnection();

	public boolean AddStipend(Stipend Stipend) {
		boolean successful = false;
		Connection con = null;
		PreparedStatement ps = null;
		con = connection.getConnection();
		try {
			
			ps = con.prepareStatement("insert into stipend(name,basic,eat,house,duty,tax,punishment,granttime, employeeId)" +
	 				                              "values (?   ,?    ,?  ,?    ,?   ,?  ,?         ,?        ,?)");
			ps.setString(1, Stipend.getName());
			ps.setString(2, Stipend.getBasic());
			ps.setString(3, Stipend.getEat());
			ps.setString(4, Stipend.getHouse());
			ps.setString(5, Stipend.getDuty());
			ps.setString(6, Stipend.getTax());
			ps.setString(7, Stipend.getPunishment());
			ps.setString(8, Stipend.getGranttime());
			ps.setInt(9,Stipend.getEmployeeid());
			int col = ps.executeUpdate();
			if(col>0)successful = true;
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			try {
				if(ps != null)ps.close();
				if(con!= null)con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
	    }
		return successful;
	}

	public ArrayList QueryStipend(int beginIndex, int endIndex) {
		ArrayList vec=new ArrayList();
		ResultSet rs=null;
		Connection con=null;
		PreparedStatement ps=null;
		
		con=connection.getConnection();
		try {
			ps=con.prepareStatement("select * from stipend limit ?,?");
			ps.setInt(1, beginIndex);
			ps.setInt(2, endIndex);
			rs=ps.executeQuery();
			rs.beforeFirst();
			while(rs.next()){
				Stipend ins=new Stipend();
				ins.setId(rs.getInt("id"));
				ins.setName(rs.getString("name"));
				ins.setBasic(rs.getString("basic"));
				ins.setEat(rs.getString("eat"));
				ins.setHouse(rs.getString("house"));
				ins.setDuty(rs.getString("duty"));
				ins.setTax(rs.getString("tax"));
				ins.setPunishment(rs.getString("punishment"));
				ins.setGranttime(rs.getString("granttime"));
				vec.add(ins);
			}
				
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				if(ps != null)ps.close();
				if(rs != null)rs.close();
				if(con!= null)con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
	    }
		return vec;
	}

	public Stipend QueryStipendById(int id) {
		Stipend ins=new Stipend();
		PreparedStatement ps=null;
		ResultSet rs=null;
		Connection con=null; 
		con=connection.getConnection();
		
		try {
			ps=con.prepareStatement("select * from stipend where id= ?");
			ps.setInt(1, id);
			rs=ps.executeQuery();
			while(rs.next()){
				ins.setId(rs.getInt("id"));
				ins.setName(rs.getString("name"));
				ins.setBasic(rs.getString("basic"));
				ins.setEat(rs.getString("eat"));
				ins.setHouse(rs.getString("house"));
				ins.setDuty(rs.getString("duty"));
				ins.setTax(rs.getString("tax"));
				ins.setPunishment(rs.getString("punishment"));
				ins.setGranttime(rs.getString("granttime"));
			}
				
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				if(ps != null)ps.close();
				if(rs != null)rs.close();
				if(con!= null)con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
	    }
		
		return ins;
		
	}

	public int QueryStipendcount() {
		int stipendcount = 0;
		Connection con=null;
		PreparedStatement ps=null;
		ResultSet rs=null;
		con=connection.getConnection();
		try {
			ps=con.prepareStatement("select * from stipend");
			rs=ps.executeQuery();
			while(rs.next()){
				stipendcount=stipendcount+1;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				if(ps != null)ps.close();
				if(rs != null)rs.close();
				if(con!= null)con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
	    }
		return stipendcount;
	}

	public boolean UpdateStipend(Stipend stipend,int id) {
		boolean successful = false;
		Connection con = null;
		PreparedStatement ps = null;
		con=connection.getConnection();
		try {
			ps = con.prepareStatement("update stipend set name=?, basic=?,eat=?, house=?,duty=?, tax=?, punishment=?, granttime=? where id=?");
			ps.setString(1,stipend.getName());
			ps.setString(2,stipend.getBasic());
			ps.setString(3,stipend.getEat());
			ps.setString(4,stipend.getHouse());
			ps.setString(5,stipend.getDuty());
			ps.setString(6,stipend.getTax());
			ps.setString(7,stipend.getPunishment());
			ps.setString(8,stipend.getGranttime());
			ps.setInt(9,id);
			int col = ps.executeUpdate();
			if(col>0)successful = true;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			try {
				if(ps != null)ps.close();
				if(con!= null)con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
	    }
		return successful;
	}

	public boolean DeletStipend(int id) {
		 boolean successful = false;
			Connection con = null;
			PreparedStatement ps = null;
			con =connection.getConnection();
			try {
				ps = con.prepareStatement("delete from stipend where id = ?");
				ps.setInt(1,id);
				int col = ps.executeUpdate();
				if(col>0)successful = true;
			} catch (SQLException e) {
				e.printStackTrace();
			} finally{
					try {
						if(ps != null)ps.close();
						if(con != null)con.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
			}
			return successful;
	}

}

⌨️ 快捷键说明

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