import org.springframework.jdbc.core.RowMapper; import java.sql.ResultSet; import java.sql.SQLException; public class CustomerRowMapper implements RowMapper { @Override public Customer mapRow(ResultSet rs, int rowNum) throws SQLException { Customer customer = new Customer(); customer.setID(rs.getLong("ID")); customer.setName(rs.getString("NAME")); customer.setAge(rs.getInt("AGE")); customer.setCreatedDate(rs.getTimestamp("created_date").toLocalDateTime()); return customer; } } import org.springframework.jdbc.core.JdbcTemplate; @Autowired private JdbcTemplate jdbcTemplate; public Customer findByCustomerId(Long id) { String sql = "SELECT * FROM CUSTOMER WHERE ID = ?"; return jdbcTemplate.queryForObject(sql, new Object[]{id}, new CustomerRowMapper()); }