hibernate配置文件再写

hibernate配置文件主要用于配置数据库连接和hibernate运行时所需的各种属性,每个hibernate配置文件对应一个Configuration对象,hibernate的配置文件有两种格式,一种是hibernate.cfg.xml,一种是hibernate.properties

在hibernate中配置数据库连接:

1).导入jar包

jar包在hibernate安装包下(hibernate-release-4.2.8.Final\lib\optional\c3p0)

2).加入配置


<!-- 配置c3p0数据源 -->


<!-- 指定连接池里最大连接数 -->
<property name="hibernate.c3p0.max_size">20</property>
<!-- 指定连接池里最小连接数 -->
<property name="hibernate.c3p0.min_size">1</property>
<!-- 指定连接池里连接的超时时长 -->
<property name="hibernate.c3p0.timeout">5000</property>
<!-- 指定连接池里最大缓存多少个Statement对象 -->
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.validate">true</property>

然后再junit类中:

@Test
public void testDoWork(){
session.doWork(new Work(){

@Override
public void execute(Connection connection) throws SQLException {
// TODO Auto-generated method stub
System.out.println(connection);
}

});
}

会在控制台输出com.mchange.v2.c3p0.impl.NewProxyConnection@8159857

 

posted @ 2016-03-01 15:05  在路上的牛小牛  阅读(187)  评论(0编辑  收藏  举报