@Repository public class EmployeeDAOImpl implements EmployeeDAO { @Autowired private DataSource dataSource; private JdbcTemplate jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; this.jdbcTemplate = new JdbcTemplate(dataSource); } @Override @Transactional(rollbackFor = Exception.class) public void addEmployee(Employee employee) throws Exception { try { String sql = "INSERT INTO employee (id, name, age) VALUES (?, ?, ?)"; jdbcTemplate.update(sql, employee.getId(), employee.getName(), employee.getAge()); } catch (DataAccessException e) { throw new Exception("Failed to add employee: " + e.getMessage()); } } // Other methods... }


上一篇:
下一篇:
切换中文