User Manual

Modifying the EmployeeDao.java File
Modify the EmployeeDao.java file in com.hp.empinfo.service package to add a new
method checkEmp(int empid) for checking whether the employee with the given empid
already exists.
After modification, the EmployeeDao.java file must appear as:
package com.hp.empinfo.service;
import java.sql.SQLException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import com.hp.empinfo.domain.Employee;
import com.hp.empinfo.domain.EmployeeRowMapper;
public class EmployeeDao extends JdbcDaoSupport implements IEmployeeDao {
public Employee getDetail(int empid) throws SQLException {
Employee employee;
employee = (Employee) getJdbcTemplate().queryForObject(
"select * from employee where empid =?",
new Object[] { empid }, new EmployeeRowMapper());
return employee;
}
public void insertDetail(int empid, String firstname, String lastname,
int age, String email) throws SQLException {
getJdbcTemplate().update("insert into employee values(?,?,?,?,?)",
new Object[] { empid, firstname, lastname, age, email });
}
public String deleteEmployee(int empid) {
getJdbcTemplate().update("delete from employee where empid= ?",
new Object[] { empid });
return "Employee deleted";
}
public Employee checkEmp(int empid) throws SQLException {
try{
Employee employee ;
employee = (Employee) getJdbcTemplate().queryForObject(
"select * from employee where empid =?",
new Object[] { empid }, new EmployeeRowMapper());
return employee;
}
catch (final EmptyResultDataAccessException e) {
return null;
}
}
}
Creating the ServiceFinder.java File
The ServiceFinder.java file is a Business Services class that contains the code to interact with
the data tier. The ServiceFinder service is used to get the Spring managed beans from
WebApplicationContext.
Integrating MyFaces into Spring 287