废话不多说,直接上代码:
<?xml version="1.0" encoding="UTF-8"?>
<!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>
<!-- property 元素用于配置Hibernate中的属性 键:值 -->
<!-- hibernate.connection.driver_class : 连接数据库的驱动 -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<!-- hibernate.connection.url : 连接数据库的地址,路径 -->
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
<!-- hibernate.connection.username : 连接数据库的用户名 -->
<property name="connection.username">guest</property>
<!-- hibernate.connection.password : 连接数据库的密码 -->
<property name="connection.password">guest</property>
<!-- show_sql: 操作数据库时,会 向控制台打印sql语句 -->
<property name="show_sql">true</property>
<!-- 数据库方言配置 org.hibernate.dialect.Oracle10gDialect (选择最短的)-->
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<!-- 配置连接池最大连接数-->
<property name="hibernate.c3p0.max_size">20</property>
<!-- 配置连接池最小连接数-->
<property name="hibernate.c3p0.min_size">2</property>
<!-- 配置连接池超时时间-->
<property name="hibernate.c3p0.timeout">5000</property>
<!-- 配置连接池最大数量-->
<property name="hibernate.c3p0.max_statements">100</property>
<!-- 配置连接池空闲检索时间-->
<property name="hibernate.c3p0.idle_test_period">150</property>
<!-- 配置连接池自增数量-->
<property name="hibernate.c3p0.acquire_increment">2</property>
<!-- 配置连接池验证-->
<property name="hibernate.c3p0.validate">false</property>
<mapping resource="com/iotek/basic/pojo/Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>
在使用c3p0连接池之前,记得导入相应的optional下的jar包
网友评论