Configure MySQL DBCP

Source: Internet
Author: User
Document directory
  • Context Configuration
  • Web. xml configuration

Refer$CATALINA_BASE

/Webapps/docs/jndi-datasource-examples-howto.html

 

Context Configuration

Configure the JNDI datasource in Tomcat by adding a declaration for your
Resource to your context
.

(

Context
Elements may be explicitly defined:

  • In$CATALINA_BASE/conf/context.xml
    File: the context
    Element Information will be loaded by all webapps.
  • In
    $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default

    File: the context element information will be loaded by all webapps of that
    Host.

  • In individual files (with a ". xml" Extension) in
    $CATALINA_BASE/conf/[enginename]/[hostname]/
    Directory. The name
    The file (less the. xml extension) will be used as the context path. Multi-Level
    Context paths may be defined using #, e.g.foo#bar.xml
    For
    Context path/foo/bar
    . The default web application may be
    Defined by using a file calledROOT.xml
    .
  • Only if a context file does not exist for the application in
    $CATALINA_BASE/conf/[enginename]/[hostname]/
    , In an individual file
    At/META-INF/context.xml
    Inside the Application Files. If the Web
    Application is packaged as a war then/META-INF/context.xml
    Will be
    Copied$CATALINA_BASE/conf/[enginename]/[hostname]/
    And renamed
    To match the application's context path. Once this file exists, it will not be
    Replaced if a new war with a newer/META-INF/context.xml
    Is placed
    In the host's appbase.
  • Inside a host
    Element in the main
    conf/server.xml
    .

)

For example:

<Context path="/DBTest" docBase="DBTest"        reloadable="true" crossContext="true">    <!-- maxActive: Maximum number of dB connections in pool. Make sure you         configure your mysqld max_connections large enough to handle         all of your db connections. Set to -1 for no limit.         -->    <!-- maxIdle: Maximum number of idle dB connections to retain in pool.         Set to -1 for no limit.  See also the DBCP documentation on this         and the minEvictableIdleTimeMillis configuration parameter.         -->    <!-- maxWait: Maximum time to wait for a dB connection to become available         in ms, in this example 10 seconds. An Exception is thrown if         this timeout is exceeded.  Set to -1 to wait indefinitely.         -->    <!-- username and password: MySQL dB username and password for dB connections  -->    <!-- driverClassName: Class name for the old mm.mysql JDBC driver is         org.gjt.mm.mysql.Driver - we recommend using Connector/J though.         Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.         -->        <!-- url: The JDBC connection url for connecting to your MySQL dB.         -->  <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"               maxActive="100" maxIdle="30" maxWait="10000"               username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"               url="jdbc:mysql://localhost:3306/javatest"/></Context>
Web. xml configuration

Now createWEB-INF/web.xml

For this test application.

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"    version="2.4">  <description>MySQL Test App</description>  <resource-ref>      <description>DB Connection</description>      <res-ref-name>jdbc/TestDB</res-ref-name>      <res-type>javax.sql.DataSource</res-type>      <res-auth>Container</res-auth>  </resource-ref></web-app>

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.