javax. naming. *; public class conndb {private connection Ct = NULL; public connection getconn () {// use the data source connection pool to connect to the database try {// create a context con = new javax. naming. initialcontext (); // obtain the data source datasource DS = (datasource) con through con. lookup ("Java: COMP/ENV/xuliugen"); // The "xuliugen" here is the name of your data source Ct = Ds. getconnection (); system. out. println ("connect
Add Resource in Tomcat 5.5/CONF/Catalina/localhost/XXXXX. XML (XXXXX. XML is your web configuration XML file)
Type = "javax. SQL. datasource"Driverclassname = "com. MySQL. JDBC. Driver"Password = "********"Maxidle = "2"Maxwait = "5000"Username = "root"Url = "JDBC: mysql: // localhost: 3306/jnestore"Maxactive = "10"/>
The above is the configuration of Tomcat 5.5. Only in this way can
Package com.action;
Import java.sql.Connection;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.sql.Statement;
Import Org.apache.tomcat.jdbc.pool.DataSource;
Import org.apache.tomcat.jdbc.pool.PoolProperties; /* * Tomcat's own JDBC Pool connection pooling technology is said to be more efficient and will be used today to sort out the following: * Requires JAR package support: Tomcat-juli
The connection of database in Web development is necessary, and the database connection pool technology optimizes the connection between dynamic page and database, which saves a lot of resources compared to the connection pool of single connection database. First, the Java connection to the MySQL database jar package is placed in the Lib directory of the Web project. second, all
Advantage: Because the HTTP protocol Web program is stateless, when the application uses JDBC, multiple request processing clients will reestablish the connection and will consume a lot of resources if the request is busy.The database connection pool is responsible for allocating, managing, and freeing the database connection, which allows the application to reuse an existing database connection instead of re-establishing it.To configure a global data
There are too many articles on the web about how to configure the Tomcat database connection pool. But I can't find an article that canTell me how to get the number of current connections for the Tomcat connection pool. If you want to monitor the health of Tomcat, thisis an
If you are using myeclipse, it is very simple and only takes three steps.First, find the context. xml configuration file in the directory where you install Tomcat. The path is [D: \ Program Files \ apachesoftware Foundation \ Tomcat 6.0 \ conf \ context. xml]Modify the file and add the following
Attribute description:Name, data source name, usually in the format of "JDBC/XXX;Type, "javax. SQL. datasource "
Take the PostgreSQL database as an example (the MySQL configuration is the same ). From runtime 5.5/common/lib
JDBC driver for PostgreSQL = http://jdbc.postgresql.org/download.html
MySQL JDBC driver = http://dev.mysql.com/downloads/connector/j/3.1.html
Then copy the corresponding JDBC Driver (JAR file) to tomcat5.5/common/lib to edit Tomcat 5.5/CONF/tomcat-users.xml, the configuration is as follows:
Unpackw
Understanding about Tomcat Thread PoolBy default, Tomcat creates a bound thread pool for each connector (the maximum number of threads is 200 ). In most cases, you do not need to change this configuration (unless you increase the maximum number of threads to meet high load requirements ). However, Tomcat prefers to cac
1. Add the configuration information in the $catalina_home/conf/server.xml, declare the specific information of the connection pool, add the following
FactoryOrg.apache.commons.dbcp.BasicDataSourceFactoryMaxwait5000Maxactive20UsernameShopadmPassword123Url jdbc:mysql://localhost/shopdb?useunicode=truecharact-erencoding=gb2312DriverclassnameCom.mysql.jdbc.DriverMaxidle102. Add the following information before $catalina_home/conf/web.xml:DB ConnectionJd
First, configure tomcat to the connection pool with sqlserver2000. jtds is used here. If this package is not available, go to http://jtds.sourceforge.net/and set it to the project lib. the following configuration is added to the Tomcat server. xml file:
Add the following configuration to the project's web. xml:
........
Add the following configuration to the hib
In fact, the two Database Connection Methods of MySQL and SQL Server are very similar.
The encoding format uses uriencoding = "UTF-8" you can set as GBK or gb2312 as needed, but I personally strongly recommend that allUTF-8
For example, Mysql Data Connection Pool settings:
1. Copy the MySQL driver file mysql. jar to Tomcat/lib.
2. Edit the directory META-INF/context. xml file in the Web application with t
very important. If this step does not exist, an error will occur, and org. apache. tomcat. DBCP. DBCP. sqlnestedexception: cannot create JDBC driver of class ''for connect URL 'null' error.Finally, in your own website's/WEB-INF/Web. xml file, add the code (refer ):Copy codeThe Code is as follows:
OK. All configurations are complete. Now you can write code to test the database connection pool. For exampl
mysql| Data | database | Database connection with the latest couple of banging, it's been a whole day. Tomcat 5.5 configuration MySQL database connection pool, online experience can not be fully used in the new environment, I write the whole process to facilitate the configuration.
1 Environment Description
JDK 1.5
Tomcat 5.5.4
MySQL 4.0.20
MySQL JDBC 3.0.15
Com
Recently, the project used tomcat jdbc pool and mybatis, the database connection pool that comes with Spring and tomcat 7, and now records the configuration of the Three Integration for emergency purposes.
Jar package:
Jar packages required by the spring framework (I will not elaborate on them here)
Mybatis-3.1.1.jarMy
[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]
When set to NiO, 。。。The MaxThreads property is useless because the thread pool of NIO is used by default, unless you use the Executor property to set a specific thread poolI have tested, use Http11nioprotocol, and set MaxThreads to 200, so that 1000 concurrent requests for the last line can still beNormally, when set to http1.1, an error will be made.Reference:Http://tomcat.apache.org/tomcat-6.0-doc/config/
Add the following lines to the configuration of a connection pool:
Code: select all
Tomcat will automatically find Code Close the resultset, statement, connection, and will automatically record which code has not released these resources using log. If it works, it is a very good feature.Refer to "Tomcat documents 'jndi datasourc
Tomcat configures sqlserver connection pool
1. Go to the conf folder directory under the Tomcat directory and find server. xmlIn the Tomcat server. xml file, set the connection statement in the DEBUG = "5" reloadable = "true" crosscontext = "true">Com. Microsoft. JDBC. sqlserver. sqlserverdriver. -->JDBC: Microsoft: sq
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.