Chinaunix首页 | 论坛 | 博客
  • 博客访问: 19001821
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类: 数据库开发技术

2008-05-28 09:25:52

一.连接mysql数据库

<bean id="dataSource"
        class
="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method
="close" abstract="false" singleton="true"
        lazy-init
="default" autowire="default" dependency-check="default">
        
<property name="driverClass">
            
<value>com.mysql.jdbc.Drivervalue>
        
property>
        
<property name="jdbcUrl">
            
<value>jdbc:mysql://192.168.0.1/databasename?useUnicode=true&characterEncoding=utf-8&autoReconnect=truevalue>
        
property>
        
<property name="user">
            
<value>usernamevalue>
        
property>
        
<property name="password">
            
<value>passwordvalue>
        
property>
        
<property name="minPoolSize">
            
<value>10value>
        
property>
        
<property name="maxPoolSize">
            
<value>20value>
        
property>
        
<property name="initialPoolSize">
            
<value>10value>
        
property>
    
bean>
    
<bean id="sessionFactory"
        class
="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        
<property name="dataSource">
            
<ref bean="dataSource">ref>
        
property>
        
<property name="hibernateProperties">
            
<props>
                
<prop key="hibernate.dialect">
                    org.hibernate.dialect.MySQLDialect
                
prop>
                
<prop key="hibernate.show_sql">
                    false
                
prop>
                
<prop key="hibernate.generate_statistics">trueprop>
                
<prop key="hibernate.cache.use_query_cache">
                    true
                
prop>
                
<prop key="hibernate.cache.use_second_level_cache">
                    true
                
prop>
                
<prop key="hibernate.cache.provider_class">
                    net.sf.ehcache.hibernate.EhCacheProvider
                
prop>
                
<prop key="hibernate.connection.provider_class">
                    org.hibernate.connection.C3P0ConnectionProvider
                
prop>
                
<prop key="hibernate.query.substitutions">
                    true 1, false 0, yes 'Y', no 'N'
                
prop>
                
<prop
                    
key="hibernate.bytecode.use_reflection_optimizer">
                    true
                
prop>
                
<prop key="hibernate.use_outer_join">trueprop>
                
<prop key="hibernate.prepare_sql">trueprop>
                
<prop key="hibernate.query.factory_class">
                    org.hibernate.hql.ast.ASTQueryTranslatorFactory
                
prop>
            
props>
        
property>

        
<property name="mappingResources">
            
<list>
                
<value>xxx/xx/xx.hbm.xmlvalue>
                
<value>xxx/xx/xx.hbm.xmlvalue>
            
list>
        
property>
    
bean>

二.连接Oracle数据库
<bean id="dataSource"
        class
="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method
="close" abstract="false" singleton="true"
        lazy-init
="default" autowire="default" dependency-check="default">
        
<property name="driverClass">
            
<value>oracle.jdbc.driver.OracleDrivervalue>
        
property>
        
<property name="jdbcUrl">
            
<value>jdbc:oracle:thin:@192.168.0.1:1521:orclvalue>
        
property>
        
<property name="user">
            
<value>usernamevalue>
        
property>
        
<property name="password">
            
<value>passwordvalue>
        
property>
        
<property name="minPoolSize">
            
<value>10value>
        
property>
        
<property name="maxPoolSize">
            
<value>20value>
        
property>
        
<property name="initialPoolSize">
            
<value>10value>
        
property>
    
bean>

    
<bean id="sessionFactory"
        class
="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        
<property name="dataSource">
            
<ref bean="dataSource">ref>
        
property>
        
<property name="hibernateProperties">
            
<props>
                
<prop key="hibernate.dialect">
                    org.hibernate.dialect.OracleDialect
                
prop>
                
<prop key="hibernate.show_sql">
                    false
                
prop>
                
<prop key="hibernate.generate_statistics">trueprop>
                
<prop key="hibernate.cache.use_query_cache">
                    true
                
prop>
                
<prop key="hibernate.cache.use_second_level_cache">
                    true
                
prop>
                
<prop key="hibernate.cache.provider_class">
                    net.sf.ehcache.hibernate.EhCacheProvider
                
prop>
                
<prop key="hibernate.connection.provider_class">
                    org.hibernate.connection.C3P0ConnectionProvider
                
prop>
                
<prop key="hibernate.query.substitutions">
                    true 1, false 0, yes 'Y', no 'N'
                
prop>
                
<prop
                    
key="hibernate.bytecode.use_reflection_optimizer">
                    true
                
prop>
                
<prop key="hibernate.use_outer_join">trueprop>
                
<prop key="hibernate.prepare_sql">trueprop>
                
<prop key="hibernate.query.factory_class">
                    org.hibernate.hql.ast.ASTQueryTranslatorFactory
                
prop>
            
props>
        
property>

        
<property name="mappingResources">
            
<list>
                
<value>xxx/xx/xx.hbm.xmlvalue>
                
<value>xxx/xx/xx.hbm.xmlvalue>
            
list>
        
property>
    
bean>
阅读(278) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~