私は、emp_leavesという名前のテーブルにデータを挿入するために使用されるdaoクラス(userdao.java)を呼び出すempbeans.javaというBeanを持っています。これはsession.iからもたらされたenameに基づいて値を挿入します小さなコード化の問題です。 "Sorry!Leaveに申し込むことができませんでした!"というメッセージを表示しています。userdao.javaにエラーはありませんか?解決してください。Javaコードの問題
ここにコードがあります。あなたはrs.next();
を見逃している
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);
}
}
コンソールに例外はありませんか? –
実際にDBに何かが挿入されていますか?これはjdbcドライバの問題です。 –
erm ...多分あなたは本当に休暇を申請できません – aldrin