0
点赞
收藏
分享

微信扫一扫

Spring + JdbcTemplate + JdbcDaoSupport examples


[url]http://www.mkyong.com/spring/spring-jdbctemplate-jdbcdaosupport-examples/[/url]

private DataSource dataSource;
private JdbcTemplate jdbcTemplate;

public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}

public void insert(Customer customer){

String sql = "INSERT INTO CUSTOMER " +
"(CUST_ID, NAME, AGE) VALUES (?, ?, ?)";

jdbcTemplate = new JdbcTemplate(dataSource);

jdbcTemplate.update(sql, new Object[] { customer.getCustId(),
customer.getName(),customer.getAge()
});

}


---------------------------------------------



public class JdbcCustomerDAO extends JdbcDaoSupport implements CustomerDAO
{
//no need to set datasource here
public void insert(Customer customer){

String sql = "INSERT INTO CUSTOMER " +
"(CUST_ID, NAME, AGE) VALUES (?, ?, ?)";

getJdbcTemplate().update(sql, new Object[] { customer.getCustId(),
customer.getName(),customer.getAge()
});

}

举报

相关推荐

0 条评论