Spring c3p0 Connection pool via hibernate configuration

Source: Internet
Author: User

Hibernate is configured first, see http://www.cnblogs.com/claricre/p/6509931.html

Then call these three packages.

To configure the Hibernate.cfg.xml file:

<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "Http://www.hi Bernate.org/dtd/hibernate-configuration-3.0.dtd "><hibernate-configuration>    <session-factory>        < Propertyname= "Hibernate.connection.provider_class">Org.hibernate.c3p0.internal.C3P0ConnectionProvider</ Property>        < Propertyname= "Hibernate.c3p0.min_size">1</ Property>        < Propertyname= "Hibernate.c3p0.max_size">5</ Property>        < Propertyname= "Hibernate.c3p0.acquire_increment">30</ Property>        < Propertyname= "Hibernate.connection.driver_class">Com.mysql.jdbc.Driver</ Property>        < Propertyname= "Hibernate.connection.url">Jdbc:mysql://localhost:3306/mydb?characterencoding=gbk</ Property>        < Propertyname= "Hibernate.connection.username">Root</ Property>        < Propertyname= "Hibernate.dialect">Org.hibernate.dialect.MySQLDialect</ Property>        < Propertyname= "Show_sql">True</ Property>        <MappingResource= "Com/model/nation.hbm.xml" />    </session-factory></hibernate-configuration>

Implementation class

 Packagecom.test;ImportJava.util.Calendar;Importjava.util.List;Importorg.hibernate.Session;Importcom.model.Nation; Public classTest { Public Static voidMain (string[] args) {LongStart =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 (); LongEnd =calendar.getinstance (). Gettimeinmillis (); System.out.println (End-start); }}

For hibernate, the efficiency of using a pool without connection is almost the same.

Spring c3p0 Connection pool via hibernate configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.