SpringJDBC Spring2.0+Java5
ちょっと、連絡も兼ねて…
Spring 2.0 m4とJava SE 5.0を使ったSpringJDBCの実装例です。Spring1.xの頃に比べて実装がシンプルになっています。
public class EmployeeDaoImpl extends SimpleJdbcDaoSupport implements EmployeeDao { private static final String EMP_QUERY = "SELECT id, name, address FROM EMPLOYEE"; private static final String INSERT_EMP = "INSERT INTO EMPLOYEE VALUES(?, ?, ?)"; private static final String DELETE_EMP = "DELETE FROM EMPLOYEE WHERE ID = ?"; public ListfindAll() { ParameterizedRowMapper pr = new ParameterizedRowMapper () { public Employee mapRow(java.sql.ResultSet rs, int rownum) throws java.sql.SQLException { Employee emp = new Employee(); emp.setId(rs.getInt("id")); emp.setName(rs.getString("name")); emp.setAddress(rs.getString("address")); return emp; } }; return getSimpleJdbcTemplate().query(EMP_QUERY, pr); } public int addEmployee(Employee emp) { return getSimpleJdbcTemplate().update( INSERT_EMP, null, emp.getName(), emp.getAddress()); } public int removeEmployee(Employee emp) { return getSimpleJdbcTemplate().update(DELETE_EMP, emp.getId()); } }