CONSTClass otherClass = new CONSTClass();
availableLeave = otherClass.serviceperiod(leaveType);
在
CONSTClass
中:private int calDaysDiff(){
String sql = "SELECT `joining` FROM `employee` WHERE `EMP_ID`='"+empId+"'";
Conn c=new Conn();
Date dateFromSql=null;
try {
Connection conn=c.createConn();
Statement s=conn.createStatement();
ResultSet rs=s.executeQuery(sql);
while (rs.next()) {
sdate=rs.getString(1);
}
dateFromSql = dateFormat.parse(sdate);
System.out.println(sdate);
} catch (Exception e) {
e.printStackTrace();
}
Calendar cal=Calendar.getInstance();
cal.setTime(dateFromSql);
Calendar cal2=Calendar.getInstance();
cal2.setTime(cal2.getTime());
int daysDiff =(int)((cal2.getTimeInMillis()-cal.getTimeInMillis())/(1000*3600*24));
return daysDiff;
}
public int serviceperiod(String Type){
int daysDiff = calDaysDiff();
int deductyear= daysDiff - 365;
int days = 0;
String sql = "SELECT numOfChildren FROM employee WHERE EMP_ID = '"+empId+"'";
String sql2= null;
Conn c=new Conn();
int numchildren= Integer.parseInt(sql);
try {
Connection conn=c.createConn();
Statement s=conn.createStatement();
numchildren = Integer.parseInt(sql);
System.out.println(sql);
}
catch (Exception e) {
e.printStackTrace();
}
if(daysDiff >= 365){
if(Type == "Casual"){
sql2 = "SELECT `LeaveNo` FROM `leave` WHERE `Leave_Id`= 'LV_1'";
}
else if(Type == "Medical"){
sql2 = "SELECT `LeaveNo` FROM `leave` WHERE `Leave_Id`= 'LV_2'";
}
else if(Type == "Annual"){
if(deductyear <=90 && deductyear >0){
sql2 = "SELECT `LeaveNo` FROM `leave` WHERE `Leave_Id`= 'LV_3'";
}
else if(deductyear <=181 && deductyear >=90){
sql2 = "SELECT `LeaveNo` FROM `leave` WHERE `Leave_Id`= 'LV_4'";
}
else if (deductyear <=273 && deductyear >=181){
sql2 = "SELECT `LeaveNo` FROM `leave` WHERE `Leave_Id`= 'LV_5'";
}
else if (deductyear <=366 && deductyear >=273){
sql2 = "SELECT `LeaveNo` FROM `leave` WHERE `Leave_Id`= 'LV_6'";
}
else{
sql2 = "SELECT `LeaveNo` FROM `leave` WHERE `Leave_Id`= 'LV_7'";
}
}
else if(Type == "Maternity"){
if(numchildren<=2){
sql2 = "SELECT `LeaveNo` FROM `leave` WHERE `Leave_Id`= 'LV_8'";
}
else{
sql2 = "SELECT `LeaveNo` FROM `leave` WHERE `Leave_Id`= 'LV_9'";
}
}
else if (Type == "Short_Leave"){
sql2 = "SELECT `LeaveNo` FROM `leave` WHERE `Leave_Id`= 'LV_10'";
}
days = Integer.parseInt(sql2);
System.out.println(sql2);
}
else{
days = 0;
}
return days;
}
calDaysDiff()
方法的作用是计算员工入职日期和今天之间的差额。 public int serviceperiod(String Type)
休假给员工。单击与休假类型相关的下拉项后,它将自动计算可用的叶子数并显示在文本框中。我想知道代码中有什么错误吗?
最佳答案
看起来像
ResultSet rs=s.executeQuery(sql);
没有给出结果。所以
while (rs.next()) {
sdate=rs.getString(1);
}
没有填写日期。如果你想解析它
dateFromSql = dateFormat.parse(sdate);
,您将获得Null Pointer Exception。
关于java - 我想获取可供Java员工使用的休假数量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33624700/