Configuration of JSP servelet data source connection pool

Source: Internet
Author: User

1. Configure the context. xml file
CopyCode The Code is as follows: <Resource
Name = "JDBC/books" // The reference name can be customized.
Auth = "Container" // specify the manager for datasource Management
Type = "javax. SQL. datasource" // specify the package name
Maxactive = "100" // maximum amount of activity
Maxidle = "30" // maximum empty limit
Maxwait = "10000" // maximum wait time
Username = "sa" // user
Password = "sa" // Password
Driverclassname = "com. Microsoft. JDBC. sqlserver. sqlserverdrier"; // connected Driver Class
Url = "JDBC: sqlserver: // localhost: 1433; databasename =" books "// URL of the Connection
/>

2. Configure the Web. xml file (the content must be the same as the information in 1) Copy codeThe Code is 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. Add an SQL driver File
Copy the driver file to the common \ Lib folder of Tomcat.
4. Add the following code to the class to obtain the data source.
Copy codeThe Code is as follows: // import the package
Import javax. Naming. context;
Import javax. Naming. initialcontext;
Import javax. Naming. namingexception;
Import javax. SQL. datasource;
// Obtain the data source link
Context Ic = new initialcontext ();
Datasource DS = (datesource) IC. Lookup ("Java: COMP/ENV/jdbc/books ");
// Obtain the connection
Connection conn = Ds. getconnection ();

Note: Some Tomcat versions in high versions can omit step 1, while others cannot. If not, an exception is thrown and the driver class cannot be found.

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.