hibernate使用c3p0连接池时hibernate.cfg.xml文件模板
hibernate使用c3p0连接池,代码书写方式与未使用连接池时一样
hibernate.cfg.xml文件模板
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory name="foo"> <!-- 配置数据库信息 --> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="connection.url">jdbc:mysql://118.89.215.39:3306/test</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.username">root</property> <property name="hibernate.connection.password">514079</property> <!-- 其他配置 --> <property name="hibernate.show_sql">true</property> <property name="hbm2ddl.auto">update</property> <!-- <mapping resource="com/hibernate/user/User.hbm.xml"/> --> <!-- 连接池 --> <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> <!-- 最大连接数 --> <property name="hibernate.c3p0.max_size">10</property> <!-- 最小连接数 --> <property name="hibernate.c3p0.min_size">5</property> <!-- 获得连接的超时时间,如果超过这个时间,会抛出异常,单位毫秒 --> <property name="hibernate.c3p0.timeout">120</property> <!-- 最大的PreparedStatement的数量 --> <property name="hibernate.c3p0.max_statements">100</property> <!-- 每隔120秒检查连接池里的空闲连接 ,单位是秒 --> <property name="hibernate.c3p0.idle_test_period">120</property> <!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 --> <property name="hibernate.c3p0.acquire_increment">2</property> <!-- 每次都验证连接是否可用 --> <property name="hibernate.c3p0.validate">false</property> <!-- 结束 --> </session-factory> </hibernate-configuration>

浙公网安备 33010602011771号