配制Spring事务和JdbcTemplate使用
百度广告
配制一个applicationContext.xml如下
< beans default - autowire = " autodetect " >
com.mysql.jdbc.Driver
< property name = " url " >
jdbc:mysql: // 192.168.1.10:3306/test?characterEncoding=UTF-8&characterSetResults=UTF-8
< property name = " username " >
root
< property name = " password " >
xx
< property name = " maxActive " >
10
< property name = " maxIdle " >
2
class = " org.springframework.jdbc.datasource.DataSourceTransactionManager " >
class = " org.springframework.jdbc.core.JdbcTemplate " >
对应的TestDaoImpl中加入这部分代码
return jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
}
String sql1 = " insert into testdb1 values('1','2') " ;
// 查询
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
String title = rs.getString( " TITLE " );
return bean;
}
List list = jdbcTemplate.query(sql1, new BeanRowMapper());
jt.execute( new ConnectionCallback() {
return null ;
}
< beans default - autowire = " autodetect " >
com.mysql.jdbc.Driver
< property name = " url " >
jdbc:mysql: // 192.168.1.10:3306/test?characterEncoding=UTF-8&characterSetResults=UTF-8
< property name = " username " >
root
< property name = " password " >
xx
< property name = " maxActive " >
10
< property name = " maxIdle " >
2
class = " org.springframework.jdbc.datasource.DataSourceTransactionManager " >
class = " org.springframework.jdbc.core.JdbcTemplate " >
对应的TestDaoImpl中加入这部分代码
return jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
}
String sql1 = " insert into testdb1 values('1','2') " ;
// 查询
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
String title = rs.getString( " TITLE " );
return bean;
}
List list = jdbcTemplate.query(sql1, new BeanRowMapper());
jt.execute( new ConnectionCallback() {
return null ;
}
编辑推荐:
下载Word文档
温馨提示:因考试政策、内容不断变化与调整,长理培训网站提供的以上信息仅供参考,如有异议,请考生以权威部门公布的内容为准! (责任编辑:长理培训)
点击加载更多评论>>