• hibernate配置文件再写


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

    在hibernate中配置数据库连接:

    1).导入jar包

    jar包在hibernate安装包下(hibernate-release-4.2.8.Finalliboptionalc3p0)

    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

  • 相关阅读:
    站立会议第七天
    站立会议第六天
    站立会议第五天
    站立会议第四天
    inotify简题
    搭建企业版yum仓
    ssh及ssh-key
    shell变量
    如何下载scp、wget、inotify及如何偷包
    rsync
  • 原文地址:https://www.cnblogs.com/zx-n/p/5231090.html
Copyright © 2020-2023  润新知