msyql 完全清除表
truncate t_user;
性能比较: JDBC > hibernate(反射太多了,影响性能)
Spring 和 JDBC的使用 (相当于SqlHelper ,在没有使用hibernate的情况下)
- 配置数据库连接池 (单例 ),由我们的Spring管理一个全局唯一的数据库连接池
- 使用jdbcTemplate (和HibernateTemplate类似 )
- 使用c3p0
- applicationContext.xml
<bean id="dataSource" class=".....ComboPooledDataSource">
<property name=""></property>
</bean>
让Spring帮我们setter setter setter ,也可以自己通过编程new 这个DataSource
完整配置:
<
?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd ">
<!-- 自动扫描与装配bean -->
<context:component-scan base-package="cn.itcast.spring.p_jdbc"></context:component-scan>
<!-- 加载外部的配置文件 -->
<context:property-placeholder location="classpath:cn/itcast/spring/p_jdbc/jdbc.properties"/>
<!-- 一、配置数据库连接池 ComboPooledDataSource -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 基本的连接信息 -->
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="user" value="${username}"></property>
<property name="password" value="${password}"></property>
<!-- 一些管理的配置 -->
<!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize" value="3"></property>
<!--连接池中保