数据库连接池的配置有多种方法:dbcp、c3p0、jndi+tomcat连接池、jndi+dbcp......
在hibernate和spring中的配置也不相同,所以我就搞懵了。
好像不用jndi也能实现配置连接池......
请各位给分析一下各自的功能,多谢了!
在hibernate和spring中的配置也不相同,所以我就搞懵了。
好像不用jndi也能实现配置连接池......
请各位给分析一下各自的功能,多谢了!
spring的配置中也是配dbcp或者c3po之类的连接池
只是实习方式的不同
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mlm?useUnicode=true&characterEncoding=UTF-8</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<!--指定连接的语言-->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property> <!--是否将运行期生成的SQL输出到日志以供调试-->
<property name="hibernate.hbm2ddl.auto">validate</property> <!-- C3P0连接池设定-->
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">5</property><!--连接池的最小连接数-->
<property name="hibernate.c3p0.max_size">30</property><!--最大连接数-->
<property name="hibernate.c3p0.timeout">1800</property><!--连接超时时间-->
<property name="hibernate.c3p0.max_statements">100</property><!--statemnets缓存大小-->
<!--每隔多少秒检测连接是否可正常使用 -->
<!--为hibernate配置连接池,推荐用c3p0,然后配置c3p0的反空闲设置idle_test_period,-->
<!--(只要小于MySQL的wait timeout即可,这句话后经证实不一定)。 -->
<property name="hibernate.c3p0.idle_test_period">121</property>
<!--当池中的连接耗尽的时候,一次性增加的连接数量,默认为3-->
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.validate">true</property> <!--映射资源-->
<mapping resource="hb/domain/Comment.hbm.xml" />
<!-- Survey -->
<mapping resource="hb/domain/survey/SurveyQuestion.hbm.xml" />
</session-factory>
</hibernate-configuration>