📄 excellentdao.java
字号:
package com.buat.excellent;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.buat.connect.Connect;
public class ExcellentDAO implements IExcellentDAO {
public String sqlInfo=null;
public int countLates=0;
public int countLeaves=0;
public int countCandidate=0;
public int countExcellent=0;
public int maxLength=0;
public PreparedStatement pst=null;
public ResultSet rs=null;
public ArrayList infoList=null;
//--------------------------------------------------------------------按优秀员工编号删除信息
public boolean delteExcellent(int excellentId) {
boolean delSuccessful=false;
Connect.getConnect();
sqlInfo="delete from Excellent where excellentId = ? ";
try {
pst=Connect.con.prepareStatement(sqlInfo);
pst.setInt(1, excellentId);
int result=pst.executeUpdate();
if(result>0){
delSuccessful=true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if(pst!=null)
try {
pst.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(rs!=null)
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return delSuccessful;
}
//--------------------------------------------------------------------分页查询所有优秀员工候选人
public ArrayList queryCandidate(int beginIndex, int endIndex) {
Connect.getConnect();
sqlInfo="select employeeId,name from Sign left join Employee on Sign.employeeId=Employee.employeeId ";
try {
pst=Connect.con.prepareStatement(sqlInfo);
rs=pst.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
//---------------------------------------------------------------------按员工编号查询候选人信息
public ArrayList queryCandidateById(int employeeId) {
return null;
}
//---------------------------------------------------------------------按员工姓名查询候选人信息
public ArrayList queryCandidateByName(String employeeName) {
return null;
}
//---------------------------------------------------------------------分页查询所有优秀员工信息
public ArrayList queryExcellent(int beginIndex, int endIndex) {
Connect.getConnect();
sqlInfo="select excellentId,name,gender,departmentId,dates from Excellent " +
"left join Employee on Excellent.employeeId = Employee.employeeId " +
"order by excellentId desc limit ? , ?";
maxLength=endIndex-beginIndex+1;
infoList=new ArrayList();
try {
pst=Connect.con.prepareStatement(sqlInfo);
pst.setInt(1, beginIndex);
pst.setInt(2, maxLength );
rs=pst.executeQuery();
while(rs.next()){
Excellent exce=new Excellent();
exce.setExcellentId(rs.getInt(1));
exce.setName(rs.getString(2));
exce.setGender(rs.getString(3));
exce.setDepartmentId(rs.getInt(4));
exce.setDates(Date.valueOf(rs.getString(5)));
infoList.add(exce);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return infoList;
}
//---------------------------------------------------------------------按优秀员工编号查询信息
public ArrayList queryExcellentById(int excellentId) {
return null;
}
//---------------------------------------------------------------------按名称查询优秀员工信息
public ArrayList queryExcellentByName(String name) {
return null;
}
public int getCountLates() {
Connect.getConnect();
sqlInfo="select count(late) from Sign where late='yes'";
return 0;
}
public int getCountLeaves() {
Connect.getConnect();
sqlInfo="select count(leaves) from Sign where leaves='yes'";
return 0;
}
public int getCountCandidate() {
// TODO Auto-generated method stub
return 0;
}
public int getCountExcellent() {
Connect.getConnect();
sqlInfo="select count(*) from Excellent";
try {
pst=Connect.con.prepareStatement(sqlInfo);
rs=pst.executeQuery();
while(rs.next()){
countExcellent=rs.getInt(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return countExcellent;
}
public static void main(String[] args){
new ExcellentDAO().getCountExcellent();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -