How to add data sources in web Development
In web development, you can use hibernate to configure data sources. However, in actual applications, you may need to connect multiple data sources,
1. Configure dataSource
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>org.logicalcobwebs.proxool.ProxoolDriver</value> </property> <property name="url"> <value>proxool.db</value> </property> </bean>
2. Configure sessionFactory
<Bean id = "sessionFactory" class = "org. springframework. orm. hibernate3.LocalSessionFactoryBean "> <property name =" dataSource "> <ref local =" dataSource "> </ref> </property> <property name =" hibernateProperties "> <props> <prop key = "hibernate. connection. provider_class "> org. hibernate. connection. c3P0ConnectionProvider </prop> <! -- Whether to output SQL statements generated during runtime to logs for debugging --> <prop key = "hibernate. show_ SQL"> true </prop> <! -- Specify the connection language --> <prop key = "dialect"> org. hibernate. dialect. MySQLDialect </prop> <! -- Whether to collect statistical data that helps performance Adjustment --> <prop key = "hibernate. generate_statistics"> true </prop> <! -- Whether to automatically reconnect --> <prop key = "hibernate. autoReconnect"> true </prop> <! -- Whether to automatically release the connection --> <prop key = "hibernate. connection. release_mode"> auto </prop> <! -- Cache configuration --> <prop key = "hibernate. cache. provider_class "> org. hibernate. cache. ehCacheProvider </prop> <prop key = "hibernate. cache. use_second_level_cache "> false </prop> <prop key =" hibernate. cache. use_query_cache "> false </prop> </props> </property> <property name =" mappingResources "> <list> <value> ing table </value> </list> </property> </bean>
3. Add jdbc support
<bean id="jdbcTemplatelr" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource"> <ref bean="dataSourceLrsql"/> </property> </bean> <bean id="basePageDao" class="com.BasePageDaoHibernateImpl"> <property name="jdbcTemplate"> <ref bean="jdbcTemplatelr"/> </property> </bean>
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!