我有一個名爲empbeans.java的bean,它調用dao類(userdao.java),用於將數據插入到名爲emp_leave的表中。它根據從session.i帶來的ename插入值一個小小的編碼問題,它顯示的信息是「Sorry!Could not Apply For Leave!」。userdao.java中是否有任何錯誤?plz解決。java代碼問題
這裏是代碼。
empbeans.java
public void apply(ActionEvent evt) {
ename = util.getSession().getAttribute("ename").toString();
boolean done= userdao.apply(this);
if (done) {
reason = "";
leavedate="";
message = "Applied For Leave Successfully!";
}
else
message = "Sorry! Could Not Apply For Leave!";
}
userdao.java
public static boolean apply(empbeans e) {
Connection con = null;
PreparedStatement ps=null;
PreparedStatement ps1=null;
try {
con = Database.getConnection();
ps1=con.prepareStatement("select eid from employee where ename=?");
ps1.setString(1,e.getEname());
ResultSet rs=ps1.executeQuery();
ps = con.prepareStatement(
"insert into emp_leaves values(?,?,?,default)");
ps.setInt(1,rs.getInt(1));
ps.setString(1,e.getLeavedate());
ps.setString(2,e.getReason());
int count = ps.executeUpdate();
return count == 1;
} catch (Exception ex) {
System.out.println("Error in inserting into time sheet -->" + ex.getMessage());
return false;
} finally {
Database.close(con);
}
}
控制檯上沒有任何異常? –
有沒有實際插入的數據庫?這可能是jdbc驅動程序的問題。 –
恩......也許你真的不能申請假 – aldrin