Hibernate 3.3.2版本
proxool 0.9.1
1.所需jar
hibernate
required文件夹下所有jar
hibernate3.jar
antlr-2.7.6.jar
dom4j.jar
javassist.jar
jta.jar
commons-collections.jar
slf4j-api.jar(最好跟slf4j-simple.jar版本一致)
slf4j-simple.jar(需另外下)
proxool
proxool.jar
proxool-cglib.jar
commons-loggin.jar(需另下)
2.编写config
src/config/hibernate/hibernate.cfg.xml
src/config/proxool.xml
proxool.xml(名字随便)
位置这里放在类路径下
<?xml version="1.0" encoding="UTF-8"?>
<proxool>
<alias>stone-proxool</alias>
<driver-url>jdbc:mysql://localhost:3306/stone</driver-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver-properties>
<property name="user" value="aguu"/>
<property name="password" value="nopass"/>
</driver-properties>
<maximum-connection-count>10</maximum-connection-count>
<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
</proxool>
hibernate.cfc.xml(也在类路径下)
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- hibernate自带连接池
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/stone</property>
<property name="hibernate.connection.username">aguu</property>
<property name="hibernate.connection.password">nopass</property>
<property name="show_sql">true</property>
<mapping resource="config/hibernate/Sort.hbm.xml"/>
</session-factory>
-->
<!--proxool连接池配置-->
<session-factory>
<!-- proxool连接池加载的类-->
<property name="hibernate.connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</property>
<!--连接池的别名,即配置连接池时起的别名-->
<property name="hibernate.proxool.pool_alias">stone-proxool</property>
<!--连接池文件的地址-->
<property name="hibernate.proxool.xml">config/proxool.xml</property>
<!--是否将运行期生成的SQL输出到日志以供调试-->
<property name="show_sql">true</property>
<mapping resource="config/hibernate/Sort.hbm.xml" />
</session-factory>
</hibernate-configuration>
3.hibernate 工具类
hibernateUtil.java
package com.aguu.core;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
private static final ThreadLocal session=new ThreadLocal();
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure("config/hibernate/hibernate.cfg.xml").buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
//取得当前线程的session
public static Session currentSession(){
Session s = (Session) session.get();
if(s==null){
s=sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession(){
Session s = (Session)session.get();
if(s!=null){
s.close();
session.set(null);
}
}
}
分享到:
相关推荐
Hibernate Proxool连接池配置总结及常遇问题
Hibernate dbpool proxool例子和jar包 数据库联接池Hibernate与proxool的应用实例。
hibernate struts spring 整合 以及itabas,xml解析log4j,缓冲技术 c3p0 proxool连接池的配置等
proxool-0.9.1(my).jar 包是我修改了proxool-0.9.1后的jar包,修改后可以完全支持spring配置,并添加了charSet配置属性,用于配置数据库链接的设置默认字符集,并且解决了proxool数据库连接池报如下错误的问题:...
hibernate+proxool+Oracle库
解决找不到org.hibernate.proxool.internal.ProxoolConnectionProvider的问题
proxool 数据库连接池用户名、密码加密处理,文件里面包含可直接使用加密的jar以及相关使用说明。
在Hibernate中配置Proxool连接池
hibernate+proxool解决mysql连接8小时自动断开问题.proxool-0.8.3.jar下载
由于项目需求的需要,我们引入了连接池。...我们采用了Hibernate,所以可以考虑hibernate自带的连接池机制,但是发现效率不高,而且Hibernate也推荐使用c3p0或Proxool连接池,在我们的项目中采用了Proxool
org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: The url cannot be null异常解决办法
本项目采用当前主流的MVC和IOC框架spring 3、优秀的ORM框架hibernate和超级厉害的proxool数据库连接池。这个工程demo,是本人在企业应用中的项目缩影,绝对实用于企业的应用。 适合朋友: 1.一直用单独的servlet和...
Struts2+Spring3+Hibernate3+Proxool_亲测成功 费大劲了.zip
nebula-test.zip,渐变插件测试线束渐变插件测试线束
是spring中引入连接池 博文链接:https://yanghaiskys.iteye.com/blog/215424
proxool-0.9.1.jar下载 hibernate3+ proxool-0.9.1配置说明 我刚配好,总结出来和大家分享下
hibernate与proxool连接池整合demo
自己写的hibernate+proxool的demo整合,亲测可用。项目可以拿来做做参考。如果有什么问题 欢迎留言作讨论。使用的话,请自己配置好proxool.xml文件 以及导入resources里面的sql(这里的sql是demo里面的entity表)
StarDB-for-Java.zip,stardb到java的一个端口,用于读取starbound的数据库文件。python库(stardb)的一个端口,用于将starbound数据库文件操作到java。