JSP servelet Data source Connection pool configuration _jsp programming

Source: Internet
Author: User
Tags auth tomcat
1. Configure Context.xml Files
Copy Code code as follows:

<resource
Name= "Jdbc/books"//reference name can be customized
Auth= "Container"//Specify Manager for admin datasource
Type= "Javax.sql.DataSource"//Specify Package name
Maxactive= "100"//maximum active capacity
maxidle= "30"//Maximum empty limit
Maxwait= "10000"//MAX Wait time
Username= "sa"/user
password= "sa"//password
Driverclassname= "Com.microsoft.jdbc.sqlserver.SQLServerDrier"; Connected Drive Classes
Url= "jdbc:sqlserver://localhost:1433;databasename="//Connection URL
/>

2 Configure the Web.xml file (the content must be the same as the information in 1)
Copy Code code as follows:

<resource-ref>
<discription>e-books datasource</discription>
<res-ref-name>jdbc/books</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

3 Adding SQL driver files
Copy the driver files to Tomcat's Common\lib folder
4 Add the following code to the class to get the data source
Copy Code code as follows:

Import Package
Import Javax.naming.Context;
Import Javax.naming.InitialContext;
Import javax.naming.NamingException;
Import Javax.sql.DataSource;
Get a link to a data source
Context IC = new InitialContext ();
DataSource ds = (datesource) ic.lookup ("Java:comp/env/jdbc/books");
Get connection
Connection conn = Ds.getconnection ();

Note: Some of the higher versions of Tomcat can omit step 2nd, others cannot, and if they cannot, throw an exception and not find a driver class
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.