Hibernate uses the Tomcat connection pool to connect to the database

Source: Internet
Author: User

[Hibernate uses the Tomcat connection pool to connect to the database] Step 1: In tomcat/conf/context. configure the connection pool information in the xml file. [html] <Resource auth = "Container" driverClassName = "com. mysql. jdbc. driver "maxActive =" 100 "maxIdle =" 30 "maxWait =" 10000 "name =" jdbc/testDB "password =" "type =" javax. SQL. dataSource "url =" jdbc: mysql: // 192.168.0.103: 3306/testDB? AutoReconnect = true & amp; useUnicode = true & amp; characterEncoding = UTF-8 "username =" root "/> where the name attribute is the data source name, usually adopt jdbc /**. the type attribute is the data source method. The driverClassName attribute is the driver name. (This is the oracle driver) username, password, database name and password url: The Path to the database to be accessed. The content composition of the url has been analyzed in the previous blog. The maxActive attribute is the maximum number of concurrent connections. If it is set to 0, there is no limit. The maxWait attribute is the maximum connection time waiting for the connection. The maxIdle attribute is the number of idle connections in the connection pool. MaxActive = "4" in the preceding settings indicates that the maximum number of connections is 4. If a connection is established, an exception occurs. MaxIdle = "2" indicates that when the database is closed (instead of actually disconnecting, it is returned to the connection pool), the maximum number of idle connections in the connection pool is two. If there is another connection, if there is no idle connection in the connection pool, but it does not reach the maximum number of maxActive concurrent connections, then establish a connection in the connection pool. Ps: some textbooks Tomcat configuration connection pool, need to add the driver package in Tomcat/lib [mysql: mysql-connector-java.jar; oracle: ojbc14.jar. ], but when you configure the connection pool under Tomcat7.0, the jar package that is not added to the driver still runs normally. Step 2: To use the Tomcat connection pool in Hibernate, you only need to configure the <SessionFactory> element as follows: [html] <? 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">

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.