In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to configure data sources in Tomcat7. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
In the operation of JDBC, opening and closing database connections is the most consuming database resources. We can store a certain amount of database connections on the server, and give these links to them whenever the program wants to connect to the database, and once the program exits the database operation, we need to return these links to the server.
The following figure is the basic concept of a data source:
1: manage database connections through Connection Pool
2: manage Connection Pool through Data Source
3: Data Source is bound by JNDI Tree
One: JNDI configuration mode
Now let's talk about how to configure Data Source on the server.
Server: Tomcat 7
1: add the following code to the tag in conf/context.xml on the Tomcat server
Click (here) to collapse or open
The parameters in the context context.xml are resolved as follows:
Where the name attribute is the name of the data source, which usually takes jdbc/**.
The driverClassName property is the driver name
Username,password, database name and password
Url: the database path to access. Among them, the content composition of url has been analyzed in the previous blog.
The maxActive property is the maximum number of concurrent connections. If set to 0, there is no limit.
The maxWait property is the time to wait for the maximum connection of the connection.
The maxIdle property is the number of idle connections in the connection pool.
There are some differences in how ORACLE is written:
two。 Modify web.xml
Open% TOMCAT_HOME%\ conf\ web.xml and add the following in front of:
MySQL Test App
DB Connection
Jdbc/shopping-this name should be the same as the previous name!
Javax.sql.DataSource
Container
3. Create a test file
Select id, name, normalprice from product
DB Test
Results
Name ${row.name}
Normalprice ${row.normalprice}
4. Add jar package
The JDBC driver mysql-connector-java-5-bin.jar is placed under% TOMCAT_HOME%\ lib and the application's WEB-INF\ lib, and copy jstl.jar and standard.jar to your WEB-INF/lib directory.
5. Configuration name
You can configure the name name= "jdbc/mldn" arbitrarily. After the configuration is complete, you need to find the data source by looking up the name. The Tomcat server used in this example code is used, so the name needs to be located when searching: java:comp/env.
Configure spring
Java:comp/env/jdbc/xxx
This is the end of the article on "how to configure data sources in Tomcat7". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.