Spring之c3p0连接池配置和使用
1、导入包:c3p0和mchange包
2、代码实现方式:
package helloworld.pools; import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import java.beans.PropertyVetoException; /**
* c3p0连接池使用方法-代码
* 导入包:c3p0和mchange包
*/
public class C3p0CodeImpl {
public static void main(String[] args) {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
try {
dataSource.setDriverClass("com.mysql.jdbc.Driver");
dataSource.setJdbcUrl("jdbc:mysql://10.15.1.200:3306/gxrdb");
dataSource.setUser("root");
dataSource.setPassword("root");
} catch (PropertyVetoException e) {
e.printStackTrace();
} // 设置数据源
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // 调用jdbcTemplate对象中的方法实现操作
String sql = "insert into user value(?,?,?)";
//表结构:id(int、自增),name(varchar 100),age(int 10)
int rows = jdbcTemplate.update(sql, null, "Tom2", 25);
System.out.println("插入行数:" + rows);
}
}
3、Spring配置实现方式
beans.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:contexnt="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <!--配置c3p0连接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!--注入属性-->
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://10.15.1.200:3306/gxrdb"></property>
<property name="user" value="root"></property>
<property name="password" value="root"></property>
</bean> </beans>
Spring之c3p0连接池配置和使用的更多相关文章
- spring hibernate4 c3p0连接池配置
c3p0-0.9.1.2.jar,c3p0-oracle-thin-extras-0.9.1.2.jar,点此下载 <bean id="dataSource" class=& ...
- Spring之c3p0连接池xml配置和使用举例
1.导入jar包 c3p0-0.9.5.2.jar mchange-commons-java-0.2.11.jar 2.源码: beans.xml <beans xmlns="http ...
- Spring中c3p0连接池的配置 及JdbcTemplate的使用 通过XML配置文件注入各种需要对象的操作 来完成数据库添加Add()方法
通过配置文件XML方法的配置 可以使用非常简练的Service类 UserService类代码如下: package com.swift; public class UserService { pri ...
- JdbcTemplae使用入门&&Spring三种连接池配置&&Spring配置文件引用外部properties文件
JdbcTemplate的使用 Spring为了各种支持的持久化技术,都提供了简单操作的模版和回调. JdbcTemplate 简化 JDBC 操作HibernateTemplate 简化 Hiber ...
- day39-Spring 15-Spring的JDBC模板:C3P0连接池配置
<!-- 配置C3P0连接池 --> <bean id="dataSource2" class="com.mchange.v2.c3p0.ComboPo ...
- C3P0连接池配置(C3P0Utils.java)
配置文件 c3p0-config.xml <?xml version="1.0" encoding="UTF-8"?> <c3p0-confi ...
- (30)java web的hibernate使用-c3p0连接池配置
hibernate支持c3p0连接池 需要导入c3p0的jar包 <!-- 配置连接驱动管理类 --> <property name="hibernate.connecti ...
- Spring c3p0连接池配置
数据库连接池 数据库连接池的基本思想就是为数据库连接建立一个“缓冲池”.预先在缓冲池中放入一定数量的连接,当需要建立数据库连接时,只需从“缓冲池”中取出一个,使用完毕之后再放回去.我们可以通过设定连接 ...
- C3p0连接池配置
在Java开发中,使用JDBC操作数据库的四个步骤如下: ①加载数据库驱动程序(Class.forName("数据库驱动类");) ②连接数据库(Connection co ...
随机推荐
- k-center问题-学习
k-center问题: In graph theory, the metric k-center or metric facility location problem is a combinator ...
- Leetcode——338. 比特位计数
题目描述:题目链接 对于求解一个十进制数转化为二进制时里面1的个数,可以先看一下概况: 十进制数 二进制数 1的个数 1 1 1 2 10 1 3 11 2 4 100 1 5 101 2 ...
- 树莓派学习笔记(3):利用VNC远程控制树莓派
转载请注明:@小五义http://www.cnblogs.com/xiaowuyi 等了一个十一假期,新买的B+终于到了.按照前两节的方法,重新安装了操作系统. 一.添加国内软件源 Rasp ...
- gitlab webhook php exec 调用 shell 脚本。shell 脚本中调用 git pull 命令无法执行。
情况如下: 我在ubuntu server 14.04 上面安装了gitlab,来托管项目代码.然后想通过gitlab的web hook 功能来做测试服务器代码自动化更新代码功能.现在遇到一个问题:就 ...
- 20155331《网络对抗》 Exp9 Web安全基础
20155331<网络对抗> Exp9 Web安全基础 实验过程 WebGoat 在终端中输入java -jar webgoat-container-7.0.1-war-exec.jar开 ...
- 云计算背后的秘密:NoSQL诞生的原因和优缺点
转载收藏一篇对nosql讲解的比较全面的文章:http://blog.csdn.net/xlgen157387/article/details/47908797 这篇文章将和大家聊聊为什么NoSQL会 ...
- 一个Python开源项目-腾讯哈勃沙箱源码剖析(上)
前言 2019年来了,2020年还会远吗? 请把下一年的年终奖发一下,谢谢... 回顾逝去的2018年,最大的改变是从一名学生变成了一位工作者,不敢说自己多么的职业化,但是正在努力往那个方向走. 以前 ...
- JNI探秘-----你不知道的FileInputStream的秘密
作者:zuoxiaolong8810(左潇龙),转载请注明出处,特别说明:本博文来自博主原博客,为保证新博客中博文的完整性,特复制到此留存,如需转载请注明新博客地址即可. 设计模式系列结束,迎来了LZ ...
- Linux删除多余内核
查看已安装内核 sudo dpkg --get-selections |grep linux-image 查看当前内核 uname -r 卸载内核 sudo apt-get remove 内核名称 配 ...
- 「功能笔记」Spacemacs+Evil备忘录
设置代理 (setq url-gateway-method 'socks) (setq socks-server '("Default server" "127.0.0. ...