Spring Java

File: context.xml

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:lang="http://www.springframework.org/schema/lang"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
                           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
                           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
                           http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd">

    
    
    
    
    
    

    
        
    
    
    
        
    

File: Main.java
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.object.SqlQuery;
class Main {
  public static void main(String args[]) throws Exception {
    ApplicationContext ac = new ClassPathXmlApplicationContext("context.xml", Main.class);
    DataSource dataSource = (DataSource) ac.getBean("dataSource");
    //DataSource mysqlDataSource = (DataSource) ac.getBean("mysqlDataSource");
    SelectCustomer selectCustomer = new SelectCustomer(dataSource);
    
    List result = selectCustomer.execute();
  }
}
class SelectCustomer extends SqlQuery {
  private static final String SQL = "select * from customer";
  SelectCustomer(DataSource ds) {
      super(ds, SQL);
  }
  protected RowMapper newRowMapper(Object[] parameters, Map context) {
      return ParameterizedBeanPropertyRowMapper.newInstance(Customer.class);
  }
}
class Customer {
  private Long id;
  private String firstName;
  private String lastName;
  private Date lastLogin;
  private String comments;
  public Long getId() {
      return id;
  }
  public void setId(Long id) {
      this.id = id;
  }
  public String getFirstName() {
      return firstName;
  }
  public void setFirstName(String firstName) {
      this.firstName = firstName;
  }
  public String getLastName() {
      return lastName;
  }
  public void setLastName(String lastName) {
      this.lastName = lastName;
  }
  public Date getLastLogin() {
      return lastLogin;
  }
  public void setLastLogin(Date lastLogin) {
      this.lastLogin = lastLogin;
  }
  public String getComments() {
      return comments;
  }
  public void setComments(String comments) {
      this.comments = comments;
  }
  @Override
  public String toString() {
      final StringBuilder sb = new StringBuilder();
      sb.append("Customer");
      sb.append("{id=").append(id);
      sb.append(", firstName='").append(firstName).append('\'');
      sb.append(", lastName='").append(lastName).append('\'');
      sb.append(", lastLogin=").append(lastLogin);
      sb.append(", comments='").append(comments).append('\'');
      sb.append('}');
      return sb.toString();
  }
}
           
       
Spring-UseParameterizedBeanPropertyRowMapper.zip( 3,657 k)