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