请教Spring JdbcTemplate的配置和使用

2025-04-30 13:09:20
推荐回答(1个)
回答1:

自力更生,在线文档一大堆!
参考spring 2.5文档 (
11.2. 利用JDBC核心类控制JDBC的基本操作和错误处理
11.2.1. JdbcTemplate类 这里面几个看看就会了)

11.2.1.2. JdbcTemplate 的最佳实践
Dao层:
public class JdbcCorporateEventDao implements CorporateEventDao {

private JdbcTemplate jdbcTemplate;

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

// JDBC-backed implementations of the methods on the CorporateEventDao follow...
}

xml配置文件

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">