zoukankan      html  css  js  c++  java
  • Tomcat 8 & JNDI Datasource

    参考:http://tomcat.apache.org/tomcat-8.0-doc/jndi-datasource-examples-howto.html

    Tomcat默认数据连接池的实现是DBCP,需要Commons DBCP和Commons Pool包,这些包被包含在tomcat/lib/tomcat-dbcp.jar中。


    ### DBCP的相关配置参数:http://commons.apache.org/proper/commons-dbcp/configuration.html
    ### 编辑`tomcat/config/context.xml`
    <Context>
        <!-- maxTotal: Maximum number of database 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 database connections to retain in pool.
             Set to -1 for no limit.  See also the DBCP documentation on this
             and the minEvictableIdleTimeMillis configuration parameter.
             -->
    
        <!-- maxWaitMillis: Maximum time to wait for a database 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 username and password for database 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 database.
             -->
    
        <Resource
            name="jdbc/TestDB"
            auth="Container"
            type="javax.sql.DataSource"
            maxTotal="100"
            maxIdle="30"
            maxWaitMillis="10000"
            username="javauser"
            password="javadude"
            driverClassName="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/javatest" />
    
    </Context>
    

    ### 编辑`WEB-INF/web.xml`
    <web-app ...>
        ...
    
        <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>
    

    ### 或者在Spring中引用
    <jee:jndi-lookup id="dataSource" jndi-name="jdbc/TestDB" />
  • 相关阅读:
    HNCU 1746: 算法4-1,4-3:定位子串
    HNCU 1330: 算法3-1:八进制数
    HNCU 1741: 算法3-2:行编辑程序
    51NOD 1073 约瑟夫环
    约瑟夫问题
    HNCU1325: 算法2-3~2-6:Big Bang(静态链表)
    指针知识复习
    html----学完总结
    html7---转载---为何img,input等内联元素可以设置高度与宽度
    html6---转载---块级元素与行内元素
  • 原文地址:https://www.cnblogs.com/hippiebaby/p/5509045.html
Copyright © 2011-2022 走看看