Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure various database connection pools in context.xml under tomcat

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to configure a variety of database connection pools in context.xml under tomcat. The article is very detailed and has certain reference value. Interested friends must read it!

The server configuration file for Tomcat6 is placed in the ${tomcat6} / conf directory. We can find server.xml and context.xml here. Of course, there are other resource files. But in this article we can only use these two, the rest will not be introduced.

1. First, you need to configure a JNDI resource for the data source. Our data source JNDI resource should be defined in the context element. In the tomcat6 version, the context element has been separated from the server.xml file and placed in a context.xml file. Because server.xml is a resource that cannot be dynamically reloaded, once the server is started, to modify this file, you have to restart the server before it can be reloaded. This is not the case with the context.xml file, which is regularly scanned by the tomcat server. Once it is found that the file has been modified (the timestamp has changed), the file is automatically reloaded without the need to restart the server. Of course, we recommend that the JNDI resources needed by the application be configured in the context.xml file instead of the server.xml file.

1. First of all, copy the driver of the database to tomcat6.0\ lib, which is the key. If there is no copy, an exception will be reported when running the program-the driver cannot be found.

2. Put the following code in the middle of Tomcat 6.0\ conf\ context.xml, such as:

Explanation: (10030 5000 for the above data)

MaxActive= "up to 100 users can connect to the data source"

MaxIdle= "if there is no user connection, 30 connections are free to wait for the user to connect"

MaxWait= "discards the connection if the connected user does not connect to the data source again within 5000 seconds"

After completing these two parts, the data source will be ready for use.

In addition, you can also configure a new context.xml under WEB-INF under project root.

/ directly connected

/ Bridge connection

C:\ Program Files\ Apache Software Foundation\ Tomcat 5.5\ conf\ context.xml

Add directly to the Context file:

Username= "he"

Password= "he"

Just go through java's jndi.

InitialContext initCtx = new InitialContext ()

DataSource ds = (DataSource) initCtx.lookup ("java:comp/env/jdbc/ database name")

Connection conn = ds.getConnection ()

The following is the configuration of various databases

1.sql2000

2.oracle

3.mysql

/ / the maximum waiting time for establishing a connection

These are all the contents of the article "how to configure various database connection pools in context.xml under tomcat". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report