How to add data sources in web Development

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.