Hello Im having problems with RowMapper<>
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.*;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.transaction.annotation.Transactional;
import javax.sql.DataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CustomerManagerImpl implements CustomerManager {
private JdbcTemplate jdbc;
public CustomerManagerImpl(DataSource dataSource) {
this.jdbc = new JdbcTemplate(dataSource);
}
@Override
public void deleteCustomer(long id) {
jdbc.update("DELETE FROM customers WHERE id=?", id);
}
@Override
public void updateCustomer(Customer c) {
jdbc.update("UPDATE customers set fullname=?,address=?,phone=?,email=? where id=?",
c.getFullname(), c.getAddress(), c.getPhone(), c.getEmail(), c.getId());
}
private RowMapper<Customer> customerMapper = new RowMapper<Customer>() {
@Override
public Customer mapRow(ResultSet rs, int rowNum) throws SQLException {
return new Customer(rs.getLong("id"),rs.getString("fullname"),rs.getString("address"),rs.getString("phone"),rs.getString("email"));
}
};
@Transactional
@Override
public List<Customer> getAllCustomers() {
return jdbc.query("SELECT * FROM customers", customerMapper);
}
@Override
public Customer getCustomerById(long id) {
return jdbc.queryForObject("SELECT * FROM customers WHERE id=?", customerMapper, id);
}
@Override
public void createCustomer(Customer c) {
SimpleJdbcInsert insertCustomer = new SimpleJdbcInsert(jdbc).withTableName("customers").usingGeneratedKeyColumns("id");
Map<String, Object> parameters = new HashMap<>(2);
parameters.put("fullname", c.getFullname());
parameters.put("address", c.getAddress());
parameters.put("phone", c.getPhone());
parameters.put("email", c.getEmail());
Number id = insertCustomer.executeAndReturnKey(parameters);
c.setId(id.longValue());
}
}
PHP Code:
java: type org.springframework.jdbc.core.RowMapper does not take parameters
java: no suitable method found for update(java.lang.String,long)
method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.String,java.lang.Object[]) is not applicable
(actual argument long cannot be converted to java.lang.Object[] by method invocation conversion)
method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.String,java.lang.Object[],int[]) is not applicable
(actual and formal argument lists differ in length)
method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.String,org.springframework.jdbc.core.PreparedStatementSetter) is not applicable
(actual argument long cannot be converted to org.springframework.jdbc.core.PreparedStatementSetter by method invocation conversion)
method org.springframework.jdbc.core.JdbcTemplate.update(org.springframework.jdbc.core.PreparedStatementCreator,org.springframework.jdbc.support.KeyHolder) is not applicable
(actual argument java.lang.String cannot be converted to org.springframework.jdbc.core.PreparedStatementCreator by method invocation conversion)
method org.springframework.jdbc.core.JdbcTemplate.update(org.springframework.jdbc.core.PreparedStatementCreator) is not applicable
(actual and formal argument lists differ in length)
method org.springframework.jdbc.core.JdbcTemplate.update(org.springframework.jdbc.core.PreparedStatementCreator,org.springframework.jdbc.core.PreparedStatementSetter) is not applicable
(actual argument java.lang.String cannot be converted to org.springframework.jdbc.core.PreparedStatementCreator by method invocation conversion)
method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.String) is not applicable
(actual and formal argument lists differ in length)
java: no suitable method found for update(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.Long)
method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.String,java.lang.Object[]) is not applicable
(actual and formal argument lists differ in length)
method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.String,java.lang.Object[],int[]) is not applicable
(actual and formal argument lists differ in length)
method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.String,org.springframework.jdbc.core.PreparedStatementSetter) is not applicable
(actual and formal argument lists differ in length)
method org.springframework.jdbc.core.JdbcTemplate.update(org.springframework.jdbc.core.PreparedStatementCreator,org.springframework.jdbc.support.KeyHolder) is not applicable
(actual and formal argument lists differ in length)
method org.springframework.jdbc.core.JdbcTemplate.update(org.springframework.jdbc.core.PreparedStatementCreator) is not applicable
(actual and formal argument lists differ in length)
method org.springframework.jdbc.core.JdbcTemplate.update(org.springframework.jdbc.core.PreparedStatementCreator,org.springframework.jdbc.core.PreparedStatementSetter) is not applicable
(actual and formal argument lists differ in length)
method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.String) is not applicable
(actual and formal argument lists differ in length)
java: type org.springframework.jdbc.core.RowMapper does not take parameters
@Override
public List<Lease> getLeasesForCustomer(final Customer c) {
return jdbc.query("SELECT * FROM leases WHERE customerId=?", new RowMapper<Lease>() {
@Override
public Lease mapRow(ResultSet rs, int rowNum) throws SQLException {
long bookId = rs.getLong("bookId");
Book book = null;
try {
book = bookManager.getBookById(bookId);
} catch (BookException e) {
log.error("cannot find book", e);
}
return new Lease(rs.getLong("id"), book, c, rs.getDate("startdate"), rs.getDate("expectedend"), rs.getDate("realend"));
}
},
c.getId());
}
PHP Code:
java: type org.springframework.jdbc.core.RowMapper does not take parameters