Spring c3p0连接池通过Hibernate配置
2017-04-04 17:53
501 查看
首先进行Hibernate配置,详见http://www.cnblogs.com/claricre/p/6509931.html
然后调用
这三个包。
配置hibernate.cfg.xml文件:
实现类
对于hibernate来说,用不用连接池的效率几乎相同。
然后调用
这三个包。
配置hibernate.cfg.xml文件:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.provider_class">org.hibernate.c3p0.internal.C3P0ConnectionProvider</property> <property name="hibernate.c3p0.min_size">1</property> <property name="hibernate.c3p0.max_size">5</property> <property name="hibernate.c3p0.acquire_increment">30</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb?characterEncoding=GBK</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property> <mapping resource="com/model/Nation.hbm.xml" /> </session-factory> </hibernate-configuration>
实现类
package com.test; import java.util.Calendar; import java.util.List; import org.hibernate.Session; import com.model.Nation; public class Test { public static void main(String[] args) { long start = Calendar.getInstance().getTimeInMillis(); Session session = HibernateUtil.getSession(); //Nation data = session.load(Nation.class, "n001"); List<Nation> list = session.createQuery("from Nation").getResultList(); for(Nation data :list){ System.out.println(data); } HibernateUtil.closeSession(); long end = Calendar.getInstance().getTimeInMillis(); System.out.println(end-start); } }
对于hibernate来说,用不用连接池的效率几乎相同。
相关文章推荐
- Spring通过XML配置c3p0连接池和dao层注解注入使用 jdbcTemplate
- Spring 结合Hibernate 配置 C3P0 连接池
- Spring 结合Hibernate 配置 C3P0 连接池
- Spring 结合Hibernate 配置 C3P0 连接池(转)
- Spring + Hibernate 配置 C3P0 连接池
- 使用spring配置C3P0连接池 并通过手动获取spring的ApplicationContext和bean对象使用库连接。
- 使用spring配置C3P0连接池 并通过手动获取spring的ApplicationContext和bean对象使用库连接
- Spring+Hibernate 配置和使用c3p0和proxool连接池
- Spring+Hibernate的连接池配置(c3p0,proxool)
- Spring+Hibernate 配置和使用c3p0和proxool连接池
- 在spring中通过hibernate配置C3P0
- Spring+Hibernate的连接池配置(c3p0,proxool)
- spring+hibernate的c3p0 连接池配置
- spring+hibernate的c3p0 连接池配置 转
- Spring 结合 Hibernate 配置 C3P0
- Hibernate中配置C3P0连接池
- 在Spring中配置C3P0与Proxool连接池
- Spring 结合 Hibernate 配置 C3P0
- jpa + hibernate 的c3p0,proxool 连接池配置
- spring中配置c3p0连接池