📄 stipenddao.java
字号:
package com.buat.stipend;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.buat.connect.Connect;
import com.buat.employee.Employee;
public class StipendDAO implements IStipendDAO {
Connect manager=new Connect();
public boolean AddStipend(Stipend stipend) {
Connection con=manager.getConnect();
boolean successful=false;
StringBuffer sql=new StringBuffer();
sql.append("insert into stipend(employeeid,basic,eat,house,duty,tax,assistance,punishment,granttime,total)");
sql.append(" values( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
PreparedStatement psmt=null;
try {
psmt=con.prepareStatement(sql.toString());
psmt.setInt(1, stipend.getEmployeeid());
psmt.setFloat(2,stipend.getBasic());
psmt.setFloat(3,stipend.getEat());
psmt.setFloat(4,stipend.getHouse());
psmt.setFloat(5,stipend.getDuty());
psmt.setFloat(6,stipend.getTax());
psmt.setFloat(7,stipend.getAssistance());
psmt.setFloat(8,stipend.getPunishment());
psmt.setDate(9,stipend.getGranttime());
psmt.setFloat(10,stipend.getTotal());
int rs=psmt.executeUpdate();
if(rs>0){
successful=true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
if(psmt !=null){
psmt.close();
}
if(con !=null){
con.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return successful;
}
public boolean DeleteStipend(int id) {
Connection con=manager.getConnect();
boolean successful=false;
StringBuffer sql=new StringBuffer();
sql.append("delete from stipend where id= ?");
PreparedStatement psmt=null;
try {
psmt=con.prepareStatement(sql.toString());
psmt.setInt(1, id);
int rs=psmt.executeUpdate();
if(rs>0){
successful=true;
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}finally{
try {
if(psmt !=null){
psmt.close();
}
if(con !=null){
con.close();
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
return successful;
}
public ArrayList QueryStipend() {
ArrayList stipendlist=new ArrayList();
Connection con=manager.getConnect();
StringBuffer sql=new StringBuffer();
sql.append("select * from stipend");
PreparedStatement psmt=null;
ResultSet rs=null;
try {
psmt=con.prepareStatement(sql.toString());
rs=psmt.executeQuery();
while(rs.next()){
Stipend stipend=new Stipend();
stipend.setId(rs.getInt("id"));
stipend.setEmployeeid(rs.getInt("employeeid"));
stipend.setBasic(rs.getFloat("basic"));
stipend.setEat(rs.getFloat("eat"));
stipend.setHouse(rs.getFloat("house"));
stipend.setDuty(rs.getFloat("duty"));
stipend.setTax(rs.getFloat("tax"));
stipend.setAssistance(rs.getFloat("assistance"));
stipend.setPunishment(rs.getFloat("punishment"));
stipend.setGranttime(rs.getDate("granttime"));
stipend.setTotal(rs.getFloat("total"));
stipendlist.add(stipend);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
if(psmt !=null){
psmt.close();
}
if(con !=null){
con.close();
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
return stipendlist;
}
public boolean UpdateStipend(Stipend stipend, int id) {
Connection con=manager.getConnect();
boolean successful=false;
StringBuffer sql=new StringBuffer();
sql.append("update stipend set employeeid=?,basic=?,eat=?,house=?,duty=?,tax=?,assistance=?,punishment=?,granttime=?,total=? where id=?");
PreparedStatement psmt=null;
try {
psmt=con.prepareStatement(sql.toString());
psmt.setInt(1, stipend.getEmployeeid());
psmt.setFloat(2,stipend.getBasic());
psmt.setFloat(3,stipend.getEat());
psmt.setFloat(4,stipend.getHouse());
psmt.setFloat(5,stipend.getDuty());
psmt.setFloat(6,stipend.getTax());
psmt.setFloat(7,stipend.getAssistance());
psmt.setFloat(8,stipend.getPunishment());
psmt.setDate(9,stipend.getGranttime());
psmt.setFloat(10,stipend.getTotal());
psmt.setInt(11,id);
int rs=psmt.executeUpdate();
if(rs>0){
successful=true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
if(psmt !=null){
psmt.close();
}
if(con !=null){
con.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return successful;
}
public int QueryCountStipend() {
int count=0;
Connection con=manager.getConnect();
StringBuffer sql=new StringBuffer();
sql.append("select count(*) from stipend");
PreparedStatement psmt=null;
try {
psmt=con.prepareStatement(sql.toString());
ResultSet rs=null;
rs=psmt.executeQuery();
while(rs.next()){
count=rs.getInt(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return count;
}
public ArrayList QueryStipendlimit(int beginIndex, int endIndex) {
ArrayList stipendlist=new ArrayList();
int maxlengh= (endIndex - beginIndex) + 1;
Connection con=manager.getConnect();
StringBuffer sql=new StringBuffer();
sql.append("select * from stipend order by id desc limit ?,?");
PreparedStatement psmt=null;
try {
psmt=con.prepareStatement(sql.toString());
psmt.setInt(1,beginIndex);
psmt.setInt(2,maxlengh);
ResultSet rs=null;
rs=psmt.executeQuery();
while(rs.next()){
Stipend stipend=new Stipend();
stipend.setId(rs.getInt("id"));
stipend.setEmployeeid(rs.getInt("employeeid"));
stipend.setBasic(rs.getFloat("basic"));
stipend.setEat(rs.getFloat("eat"));
stipend.setHouse(rs.getFloat("house"));
stipend.setDuty(rs.getFloat("duty"));
stipend.setTax(rs.getFloat("tax"));
stipend.setAssistance(rs.getFloat("assistance"));
stipend.setPunishment(rs.getFloat("punishment"));
stipend.setGranttime(rs.getDate("granttime"));
stipend.setTotal(rs.getFloat("total"));
stipendlist.add(stipend);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return stipendlist;
}
public Stipend QueryEmployeeid(Employee employee) {
Connection con=manager.getConnect();
StringBuffer sql=new StringBuffer();
sql.append("select * from employee where employeeid=?");
Stipend stipend=new Stipend();
PreparedStatement psmt=null;
ResultSet rs=null;
try {
psmt=con.prepareStatement(sql.toString());
psmt.setInt(1, employee.getEmployeeId());
rs=psmt.executeQuery();
while(rs.next()){
if (rs.getInt(1)==employee.getEmployeeId()) {
stipend.setEmployeeid(rs.getInt(1));
} else {
stipend.setEmployeeid(0);
}
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
if(psmt !=null){
psmt.close();
}
if(con !=null){
con.close();
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
return stipend;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -