4-04.jdbcTemplate简单使用讲解




package com.gyf.test; import com.gyf.service.IUserService; import org.apache.commons.dbcp.BasicDataSource; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.jdbc.core.JdbcTemplate; import javax.sql.DataSource; public class Lesson04 { @Test public void test1() throws Exception { //1.创建数据源 BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql:///spring_day04"); dataSource.setUsername("root"); dataSource.setPassword("123456"); //2.创建jdbcTemplate JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.update("update t_user set username = ? where id = ?","zzz",1); } }




浙公网安备 33010602011771号