
hello.i have a problem in inserting data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting data into database based on this ename.but it displays a message that "Sorry! Could Not Enter Details into Time Sheet!".can any one help me plz.
empbeans.java:
public void sheet() {
ename = util.getSession().getAttribute("ename").toString();
boolean done = userdao.sheet(pid, ptime, rtime, workdone,ename);
if (done) {
pid = ptime = rtime = 0;
workdone = leavedate = "";
message = "Entered details into Time Sheet Successfully!";
} else {
message = "Sorry! Could Not Enter Details into Time Sheet!";
}
}
userdao.java
public static boolean sheet(int pid,int ptime,int rtime,String workdone,String ename) {
Connection con = null;
PreparedStatement ps1 = null;
PreparedStatement ps2=null;
ResultSet rs=null;
try {
con = Database.getConnection();
ps1=con.prepareStatement("select eid from employee where ename=?");
ps1.setString(1, ename);
rs=ps1.executeQuery();
ps2 = con.prepareStatement(
"insert into emp_timesheet values(?,sysdate,?,?,?,?)");
ps2.setInt(1,rs.getInt(1));
ps2.setInt(2, pid);
ps2.setInt(3, ptime);
ps2.setInt(4, rtime);
ps2.setString(5, workdone);
int count = ps2.executeUpdate();
return count == 1;
} catch (Exception ex) {
System.out.println("Error in inserting into time sheet -->" + ex.getMessage());
return false;
} finally {
Database.close(con);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.