013_JDBC模板使用第三方连接池
生活随笔
收集整理的這篇文章主要介紹了
013_JDBC模板使用第三方连接池
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一. Spring的JDBC模板使用DBCP連接池例子
1. 創建一個名為SpringJdbcDBCP的Java工程, 同時拷入相關jar包
2. 創建SpringJdbc.java
package com.lywgames.springjdbc;import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.jdbc.core.JdbcTemplate;public class SpringJdbc {public static void main(String[] args) {ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");JdbcTemplate jdbcTemplate = context.getBean(JdbcTemplate.class);// 刪除操作int result = jdbcTemplate.update("delete from user where id=?", 993);System.out.println("result = " + result);context.close();} }3. 在src目錄下創建applicationContext.xml
4. 運行項目
二. Spring的JDBC模板使用C3P0連接池例子
1. 創建一個名為SpringJdbcC3P0的Java工程, 同時拷入相關jar包
2. 創建SpringJdbc.java
package com.lywgames.springjdbc;import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.jdbc.core.JdbcTemplate;public class SpringJdbc {public static void main(String[] args) {ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");JdbcTemplate jdbcTemplate = context.getBean(JdbcTemplate.class);// 修改操作int result = jdbcTemplate.update("update user set username=?,password=? where id=?", "張飛", "1a_32b", 1000);System.out.println("result = " + result);context.close();} }3. 在src目錄下創建applicationContext.xml
4. 運行項目
總結
以上是生活随笔為你收集整理的013_JDBC模板使用第三方连接池的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 012_JDBC模板
- 下一篇: 014_Spring事务