我的SSH JDBC数据源配置
作者: Yan
?
hibernate.hbm.xml:
?
MS SQL:
<hibernate-configuration><session-factory><property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property><property name="hibernate.connection.url">jdbc:sqlserver://172.20.32.72:1433;DatabaseName=chbms</property><property name="hibernate.connection.password">123456</property><property name="hibernate.connection.username">sa</property><property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property><property name="hibernate.show_sql">true</property><property name="hibernate.format_sql">false</property><property name="hibernate.hbm2ddl.auto">none</property><!-- 基礎(chǔ)包 --><mapping class="..."/>...</session-factory> </hibernate-configuration> ?
?
Oracle:
<hibernate-configuration><session-factory> <!--jdbc 驅(qū)動(dòng) --> <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property><!-- 連接字符串 --> <property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:[databaseName]</property><!-- 用戶名 --> <property name="hibernate.connection.username">[用戶名]</property><!-- 數(shù)據(jù)庫密碼 --> <property name="hibernate.connection.password">[密碼]</property> <property name="hibernate.connection.pool_size">1</property> <!-- dialect 每種數(shù)據(jù)庫都有其相對的dialect --> <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property> <!-- 是否將運(yùn)行期間的生成的SQL輸出到日志已供調(diào)試 --> <property name="hibernate.show_sql">true</property><!-- 是否使用外連接 --> <property name="hibernate.use_outer_join">true</property> <!-- 事務(wù)管理類型,這里是jdbc 的 --> <property name="hibernate.transaction.factory_class"> org.hibernate.transaction.JDBCTransactionFactory</property> <mapping class="com.xx.User"/>...</session-factory> </hibernate-configuration>?
?
MySql:
<?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-configuration><session-factory> <!--jdbc 驅(qū)動(dòng) --> <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property><!-- 連接字符串 --> <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/[dababaseName]</property><!-- 用戶名 --> <property name="hibernate.connection.username">root</property><!-- 數(shù)據(jù)庫密碼 --> <property name="hibernate.connection.password">123456</property> <property name="hibernate.connection.pool_size">1</property> <!-- dialect 每種數(shù)據(jù)庫都有其相對的dialect 這里是mysql --> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <!-- 是否將運(yùn)行期間的生成的SQL輸出到日志已供調(diào)試 --> <property name="hibernate.show_sql">true</property><!-- 是否使用外連接 --> <property name="hibernate.use_outer_join">true</property> <!-- 事務(wù)管理類型,這里是jdbc 的 --> <property name="hibernate.transaction.factory_class"> org.hibernate.transaction.JDBCTransactionFactory</property> <mapping class="com.xx.User"/></session-factory> </hibernate-configuration>?
?
SpringContext.xml:
?
c3p0(以oracle為例,根據(jù)數(shù)據(jù)庫不同修改相應(yīng)屬性值):
<bean id="xxxDS"class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass"><value>oracle.jdbc.driver.OracleDriver</value></property><property name="jdbcUrl"><value>jdbc:oracle:thin:@127.0.0..1:1521:xxx</value></property><property name="user" value="xxx" /><property name="password" value="xxx" /><property name="minPoolSize"><value>1</value></property><property name="maxPoolSize"><value>20</value></property><property name="maxIdleTime"><value>1800</value></property><property name="acquireIncrement"><value>2</value></property><property name="maxStatements"><value>0</value></property><property name="initialPoolSize"><value>2</value></property><property name="idleConnectionTestPeriod"><value>1800</value></property><property name="acquireRetryAttempts"><value>30</value></property><property name="breakAfterAcquireFailure"><value>true</value></property><property name="testConnectionOnCheckout"><value>false</value></property> </bean><bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref local="forwarderDS" /> </property> <property name="packagesToScan"><list><value>com.xxx.entity</value><value>com.xxx.yyy.entity</value></list></property><property name="hibernateProperties"> <props><prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.use_outer_join">true</prop> <prop key="hibernate.jdbc.batch_size">50</prop> <prop key="hibernate.jdbc.fetch_size">5</prop> <prop key="hibernate.connection.pool_size">2</prop> <prop key="hibernate.connection.autocommit">false</prop> <prop key="hibernate.cache.use_query_cache">false</prop> <prop key="hibernate.max_fetch_depth">1</prop> <prop key="hibernate.bytecode.use_reflection_optimizer">true</prop> </props> </property> </bean> ?
?
總結(jié)
以上是生活随笔為你收集整理的我的SSH JDBC数据源配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 静态路由(静态汇总路由,静态默认路由,负
- 下一篇: struts2上传文件类型限制