Study Tomcat structure to resolve data source connection database

Source: Internet
Author: User
Tags add define auth connection pooling contains sql mysql tomcat
Solution | Connection Database | Data source tomcat Server is composed of a series of configurable Russian components, the core of which is the Catalina servlet container, the following is the component relationship

< server><!--top-level element, is the top-level element of a Tomcat instance, and can contain one or more service-->

< service><!--connector element, contains a engine element, and one or more connector elements that share the same engine-->

< connector><!--components that actually interact with the customer-->

< engine><!--Container class element that can contain multiple host elements-->

< host><!--Define a virtual host that can contain one or more Web applications-->

< context><!--The most frequently used elements, each context represents the application running on a virtual host-->

......................</context>

Nested class elements can be added to container components such as:< logger>< value>< realm> elements

So in Server.xml, we just add that there is no context tag in the tomcat5.0.x, so we used to always add a location error without knowing the directory structure

< context path= "/data" docbase= "Data" debug= "0" reloadable= "true" >

<!--here pay special attention to pointing out the relative path of Web application-->
< Resource name= "Jdbc/sunny" scope= "shareable" auth= "Container"
Type= "Javax.sql.DataSource" ></resource>
< Resourceparams name= "Jdbc/sunny" >
< parameter>
< name>factory</name>
< value>org.apache.commons.dbcp.basicdatasourcefactory</value>
</parameter>
< parameter>
< name>removeabandoned</name>
< value>true</value>
</parameter>
< parameter>
< name>logabandoned</name>
< value>true</value>
</parameter>
<!--DBCP database connection Settings-->
< parameter>
< name>url</name>
< value>jdbc:mysql://localhost:3306/sony</value>
</parameter>
< parameter>
< name>driverclassname</name><!--< value>com.mysql.jdbc.driver</value>-->
< value>org.gjt.mm.mysql.driver</value>
</parameter>
< parameter>
< name>username</name>
< value>root</value>
</parameter>
< parameter>
< name>password</name>
< value></value>
</parameter>

<!--DBCP connection pooling Options-->
< parameter>
< name>maxwait</name>
< value>3000</value>
</parameter>
< parameter>
< name>maxidle</name>
< value>100</value>
</parameter>
< parameter>
< name>maxactive</name>
< value>10</value>
</parameter>
</resourceparams>

</context>

In the JSP page

Javax.naming.Context CTX = new Javax.naming.InitialContext

DataSource ds = (DataSource) ctx.lookup ("Java:comp/env/jdbc/sunny")

Connection conn = Ds.getconnection (); The Tomcat server is composed of a series of configurable Russian components, the core of which is the Catalina servlet container, and the following is the component relationship

< server><!--top-level element, is the top-level element of a Tomcat instance, and can contain one or more service-->

< service><!--connector element, contains a engine element, and one or more connector elements that share the same engine-->

< connector><!--components that actually interact with the customer-->

< engine><!--Container class element that can contain multiple host elements-->

< host><!--Define a virtual host that can contain one or more Web applications-->

< context><!--The most frequently used elements, each context represents the application running on a virtual host-->

......................</context>

Nested class elements can be added to container components such as:< logger>< value>< realm> elements

So in Server.xml, we just add that there is no context tag in the tomcat5.0.x, so we used to always add a location error without knowing the directory structure

< context path= "/data" docbase= "Data" debug= "0" reloadable= "true" >

<!--here pay special attention to pointing out the relative path of Web application-->
< Resource name= "Jdbc/sunny" scope= "shareable" auth= "Container"
Type= "Javax.sql.DataSource" ></resource>
< Resourceparams name= "Jdbc/sunny" >
< parameter>
< name>factory</name>
< value>org.apache.commons.dbcp.basicdatasourcefactory</value>
</parameter>
< parameter>
< name>removeabandoned</name>
< value>true</value>
</parameter>
< parameter>
< name>logabandoned</name>
< value>true</value>
</parameter>
<!--DBCP database connection Settings-->
< parameter>
< name>url</name>
< value>jdbc:mysql://localhost:3306/sony</value>
</parameter>
< parameter>
< name>driverclassname</name><!--< value>com.mysql.jdbc.driver</value>-->
< value>org.gjt.mm.mysql.driver</value>
</parameter>
< parameter>
< name>username</name>
< value>root</value>
</parameter>
< parameter>
< name>password</name>
< value></value>
</parameter>

<!--DBCP connection pooling Options-->
< parameter>
< name>maxwait</name>
< value>3000</value>
</parameter>
< parameter>
< name>maxidle</name>
< value>100</value>
</parameter>
< parameter>
< name>maxactive</name>
< value>10</value>
</parameter>
</resourceparams>

</context>

In the JSP page

Javax.naming.Context CTX = new Javax.naming.InitialContext

DataSource ds = (DataSource) ctx.lookup ("Java:comp/env/jdbc/sunny")

Connection conn = Ds.getconnection ();

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.