<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    qiyadeng

    專注于Java示例及教程
    posts - 84, comments - 152, trackbacks - 0, articles - 34

    Tomcat中配置MySQL連接池

    Posted on 2005-10-11 10:13 qiyadeng 閱讀(2707) 評論(0)  編輯  收藏 所屬分類: J2EE

    1.把驅(qū)動拷貝到%TOMCAT_HOME%/common/lib目錄下
    2.新建數(shù)據(jù)庫表,并向表中添加記錄

    1 use test;
    2 create table testdata (
    3        id int not null auto_increment primary key,
    4        foo varchar(25), 
    5        bar int);
    6insert into testdata values(null'hello'12345);
    7


    3.在%TOMCAT_HOME%/config/server.xml文件中加入如下一段配置信息(在</Host>之前)

     1        <!--數(shù)據(jù)庫連接池配置-->
     2    <!--path:Your webApp directory-->
     3<Context path="/WS4Motel" docBase="WS4Motel"
     4        debug="5" reloadable="true" crossContext="true">
     5
     6    <!-- maxActive: Maximum number of dB connections in pool. Make sure you
     7         configure your mysqld max_connections large enough to handle
     8         all of your db connections. Set to 0 for no limit.
     9         -->
    10
    11    <!-- maxIdle: Maximum number of idle dB connections to retain in pool.
    12         Set to -1 for no limit.  See also the DBCP documentation on this
    13         and the minEvictableIdleTimeMillis configuration parameter.
    14         -->
    15
    16    <!-- maxWait: Maximum time to wait for a dB connection to become available
    17         in ms, in this example 10 seconds. An Exception is thrown if
    18         this timeout is exceeded.  Set to -1 to wait indefinitely.
    19         -->
    20
    21    <!-- username and password: MySQL dB username and password for dB connections  -->
    22
    23    <!-- driverClassName: Class name for the old mm.mysql JDBC driver is
    24         org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
    25         Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
    26         -->
    27    
    28    <!-- url: The JDBC connection url for connecting to your MySQL dB.
    29         The autoReconnect=true argument to the url makes sure that the
    30         mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
    31         connection.  mysqld by default closes idle connections after 8 hours.
    32         -->
    33
    34  <Resource name="jdbc/WS4Motel" auth="Container" type="javax.sql.DataSource"
    35               maxActive="100" maxIdle="30" maxWait="10000"
    36               username="root" password="83072674" driverClassName="com.mysql.jdbc.Driver"
    37               url="jdbc:mysql://localhost:3306/test?autoReconnect=true"/>
    38
    39</Context>
    40        <!--數(shù)據(jù)庫連接池配置-->
    41

     

     4.寫個(gè)簡單程序測試下:

     1<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
     2<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
     3
     4<sql:query var="rs" dataSource="jdbc/TestDB">
     5select id, foo, bar from testdata
     6</sql:query>
     7
     8<html>
     9  <head>
    10    <title>DB Test</title>
    11  </head>
    12  <body>
    13
    14  <h2>Results</h2>
    15  
    16<c:forEach var="row" items="${rs.rows}">
    17    Foo ${row.foo}<br/>
    18    Bar ${row.bar}<br/>
    19</c:forEach>
    20
    21  </body>
    22</html>
    23
    主站蜘蛛池模板: 亚洲精品视频在线观看免费| 国产亚洲人成网站在线观看不卡 | 亚洲综合图片小说区热久久| 久久免费观看国产精品88av| 亚洲成色www久久网站夜月| 免费人成在线观看视频高潮| 国产亚洲精品a在线无码| 免费无码又爽又刺激网站直播 | 午夜免费1000部| 亚洲伊人久久大香线蕉在观| 亚洲综合免费视频| 亚洲av片不卡无码久久| 亚洲国产成人久久一区久久| 妇女自拍偷自拍亚洲精品| 免费一级一片一毛片| 亚洲一区二区三区免费| 精品久久久久久亚洲| 一级毛片在线观看免费| 亚洲精品一区二区三区四区乱码| 99精品国产免费久久久久久下载| 亚洲欧洲无卡二区视頻| 亚洲第一区在线观看| 热久久这里是精品6免费观看| 亚洲AV日韩AV永久无码久久| 日本免费一区二区在线观看| 亚洲欧美日韩综合久久久| 免费成人av电影| 国产成人一区二区三区视频免费| 亚洲最大免费视频网| 日本媚薬痉挛在线观看免费| 精选影视免费在线 | 亚洲黄色网址在线观看| 麻豆国产VA免费精品高清在线| 一个人免费观看视频在线中文| 亚洲国产精品无码久久久秋霞2 | 青青青亚洲精品国产| 亚洲人成网7777777国产| 国产免费女女脚奴视频网| 丝袜熟女国偷自产中文字幕亚洲| 一级毛片在线免费观看| 亚洲av永久无码天堂网|