1,Spring 中封装了一个可以操作数据库的对象(JDBCTemplate:jdbc模板),这个对象封装了JDBC技术
2,与DBUtil中的QueryRunner对象非常相似
3,操作
(1)导包
2,准备数据库
3,编写测试类
package com.songyan.jdbc;import java.beans.PropertyVetoException;import org.springframework.jdbc.core.JdbcTemplate;import com.mchange.v2.c3p0.ComboPooledDataSource;/*** 演示jdbc模板* @author sy**/ public class Demo {//测试模板类 public static void main(String[] args) throws PropertyVetoException {//准备连接池ComboPooledDataSource dataSource=new ComboPooledDataSource();dataSource.setDriverClass("com.jdbc.mysql.Driver");dataSource.setJdbcUrl("jdbc:mysql:///day06");dataSource.setUser("root");dataSource.setPassword("247418");//创建jdbc模板JdbcTemplate jdbcTemplate=new JdbcTemplate();//设置连接池 jdbcTemplate.setDataSource(dataSource);//书写sql并执行String sql="insert into users values ('1','zhangsan')" ;jdbcTemplate.update(sql);//jdbcTemplate.c } }