DataSource dataSource = ... //
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
String sql = "SELECT * FROM customer";
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
while(rowSet.next())
{
String firstName = rowSet.getString("first_name");
String lastName = rowSet.getString("last_name");
System.out.println("Vorname: " + firstName);
System.out.println("Nachname: " + lastName);
System.out.println("---”);
}
OR
String sql = "SELECT * FROM customer";
List<Customer> customerList = jdbcTemplate.query(sql, new RowMapper<Customer>() {
@Override
public Customer mapRow(ResultSet rs, int rowNum) throws SQLException
{
Customer customer = new Customer();
customer.setFirstName(rs.getString("first_Name"));
customer.setLastName(rs.getString("first_Name"));
customer.setEmail(rs.getString("email"));
return customer;
}
});