第一种方式:.Spring常规的数据库连接方法:

 1 @RunWith(SpringJUnit4ClassRunner.class)
 2 @ContextConfiguration(locations="classpath:applicationContext.xml")
 3 public class jdbcTemplateTest1 {
 4 /*    @Test
 5     public void test1(){
 6     //1.创建数据库连接池(Spring)
 7         DriverManagerDataSource dataSource = new DriverManagerDataSource();
 8     //2.设置参数
 9         //获取驱动
10         dataSource.setDriverClass("com.mysql.jdbc.Driver");
11         //连接数据库
12         dataSource.setJdbcUrl("jdbc:mysql:///springtest");
13         dataSource.setUser("root");
14         dataSource.setPassword("123");
15     //3.创建jdbcTemplate
16         JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
17         jdbcTemplate.execute("update t_user set name='tom' where id=3");
18     } */   
19     @Autowired
20     private JdbcTemplate jdbcTemplate;
21     @Test
22     public void test2(){
23     jdbcTemplate.execute("update t_user set name='tom' where id=1");
24 }
25 }
常规方案

相关文章:

  • 2021-06-22
  • 2022-12-23
  • 2021-07-24
  • 2021-10-22
  • 2021-11-21
猜你喜欢
  • 2022-12-23
  • 2021-08-20
  • 2022-12-23
  • 2021-11-11
  • 2021-12-16
  • 2021-11-28
相关资源
相似解决方案