62,615
社区成员
发帖
与我相关
我的任务
分享
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- hibernate配置 -->
<hibernate-configuration>
<session-factory>
<!-- 数据库方言 -->
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<!-- 数据库连接字符串 -->
<property name="connection.url">
jdbc:mysql://localhost/java_demo
</property>
<!-- 数据库用户名 -->
<property name="connection.username">root</property>
<!-- 密码 -->
<property name="connection.password">root</property>
<!-- 数据库驱动 -->
<property name="connectiosn.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- 是否显示执行的sql语句 -->
<property name="show_sql">true</property>
<!-- c3p0配置 -->
<!-- 指定connection的提供者 -->
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.max_size">2</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.timeout">1</property>
<property name="hibernate.c3p0.max_statements">1</property>
<property name="hibernate.c3p0.validate">false</property>
<property name="hibernate.c3p0.acquire_increment">0</property>
<property name="hibernate.c3p0.idle_test_period">1</property>
<!-- 配置映射文件 -->
<mapping resource="hibernate/c3p0/entity/Student.hbm.xml" />
</session-factory>
</hibernate-configuration>
public static void main(String[] args) {
Configuration config=new Configuration().configure();
SessionFactory factory=config.buildSessionFactory();
//获取4个session
Session session=factory.openSession();
Session session2=factory.openSession();
Session session3=factory.openSession();
Session session4=factory.openSession();
//获取4个Connection对象
Connection c1=session.connection();
Connection c2=session2.connection();
Connection c3=session3.connection();
Connection c4=session4.connection();
}