Configure Tomcat connection pool on the web page

Source: Internet
Author: User

Take tomcat4.1.29 as an Example

1. Copy the driver file of the database to Tomcat in the WEB-INF/lib folder under your webapp

2, start Tomcat, enter the administrator interface (Tomcat home page has a link in the upper left corner, if you do not know the password, please open the conf folder in the Tomcat file under the tomcat-users.xml file, with notepad can open, it contains the admin user name and password, and the admin default password is blank)

3. Click Tomcat server> service> host> context> resources> data sources in the left column.

4. In the data source actions drop-down box on the right, select create new data source >>> and configure the datasource information.

Take MSSQL as an example:
JNDI name: JDBC/MSSQL
Data source URL: JDBC: Microsoft: sqlserver: // 192.168.0.52: 1433; databasename = Abu
JDBC Driver Class: COM. Microsoft. JDBC. sqlserver. sqlserverdriver
User name: Abu
Password: Abu
Max. Active connections: 4
Max. Active connections: 2
Max. Wait for connection: 5000
Validation query: // you can leave it empty.

5. Click Save> Commit Changes in the header of the page.

6. Restart the service and enter the following in the test page:Code

<% @ Page import = "Java. SQL. *" %>
<% @ Page import = "javax. SQL. *" %>
<% @ Page import = "javax. Naming. *" %>
<%
Datasource DS = NULL;
Try {
Initialcontext CTX = new initialcontext ();
DS = (datasource) CTX. Lookup ("Java: COMP/ENV/jdbc/MSSQL ");
Connection conn = Ds. getconnection ();
Statement stmt = conn. createstatement ();
String strsql = "select * From TTT ";
Resultset rs = stmt.exe cutequery (strsql );
While (Rs. Next ()){
System. Out. println (Rs. getstring (1 ));
}
}
Catch (exception ex ){
Ex. printstacktrace ();
}
%>

7. You should be able to see the printed items on the console.

I hope this will help you.

 

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.