Configure Tomcat database connection pool in eclipse

Source: Internet
Author: User

The premise is to put the required msutil. Jar MSSQLServer. Jar msbase. Jar mssqlserver4v65. Jar under tomcat/common/lib.

1,Copy the JDBC driver of the database to % atat_home %/common/lib and webcontent/Web-INF/lib of the eclipse project.

2,The node of the server. XML web program on the eclipse Server:

<Context docbase = "filemanager" Path = "/filemanager" reloadable = "true" Source = "org. Eclipse. JST. J2EE. SERVER: filemanager">

</Context>

Add the following content:
<Resource Name = "JDBC/filedb" auth = "Container"
Type = "javax. SQL. datasource" maxactive = "100" maxidle = "30"
Maxwait = "10000" username = "sa" Password = "123"
Driverclassname = "com. Microsoft. JDBC. sqlserver. sqlserverdriver"
Url = "JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = filedb"/>

3,Create an XML file with the same name as your web folder under % atat_home %/CONF/Catalina/localhost (my file is filemanager. XML)  
This step is 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'. Add the following content to the file:

<? XML version = "1.0" encoding = "UTF-8"?>
<Context>
<Resource Name = "JDBC/filedb" auth = "Container"
Type = "javax. SQL. datasource" maxactive = "100" maxidle = "30"
Maxwait = "10000" username = "sa" Password = "123"
Driverclassname = "com. Microsoft. JDBC. sqlserver. sqlserverdriver"
Url = "JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = filedb"/>
</Context>

4,Modify the Web. xml under webcontent/Web-INF of the eclipse project and add the following content before </Web-app>:

<Resource-ref>
<Description> dB connection </description>
<Res-ref-Name> JDBC/filedb </RES-ref-Name>
<Res-type> javax. SQL. datasource </RES-type>
<Res-auth> container </RES-auth>
</Resource-ref>

5,Create a new dbtest. jsp file under webcontent.

<% @ Page contenttype = "text/html; charset = GBK" %>
<% @ Page import = "Java. SQL. *" %>
<% @ Page import = "javax. SQL. *" %>
<% @ Page import = "javax. Naming. *" %>
<%
Try {
Context initcontext = new initialcontext ();
Context envcontext =
(Context) initcontext. Lookup ("Java:/COMP/ENV ");
Datasource DS =
(Datasource) envcontext. Lookup ("JDBC/filedb ");
Connection conn = Ds. getconnection ();
 
If (! Conn. isclosed ())

Out. println ("database connection test succeeded ");
Conn. Close ();
}
Catch (sqlexception e ){
Out. println (E. tostring ());
}
%>

Restart the server and run dbtest. jsp. Then, restart _^.

Note: mssqlserver4v65 is not imported. JAR file, causing the program to appear Org. apache. tomcat. DBCP. DBCP. sqlnestedexception: cannot create JDBC driver of class ''for connect URL 'null' error.

 

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.