Jeffrey's Sky

          Go with wind
          隨筆 - 14, 文章 - 1, 評論 - 15, 引用 - 0

          導航

          <2010年8月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          開源軟件問題記錄系列 之一 在 Tomcat 中設置 Datasource

          Tomcat提供了靈活且簡單的JNDI及Datasource設置方式。

          這里,記錄我在學習應用過程中的問題。

          1. 首先要在你的自己的應用程序中WEB-INF/web.xml 中添加一個Resource-ref, 指定Datasource 的 JNDI。
              <resource-ref>
                <description>DB Connection</description>
                <res-ref-name>jdbc/storedb</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
            </resource-ref>
          2. 在Tomcat的 config/context.xml中添加Resource。 (本例中使用的是MySql作為 DB)

             <!-- 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/storedb" auth="Container" type="javax.sql.DataSource"
                         maxActive="100" maxIdle="30" maxWait="10000"
                         username="root" password="passw0rd" driverClassName="com.mysql.jdbc.Driver"
                         url="jdbc:mysql://localhost:3306/storedb"/>


          posted on 2010-08-02 10:51 Jeffrey Feng 閱讀(227) 評論(0)  編輯  收藏 所屬分類: 開源技術

          主站蜘蛛池模板: 越西县| 彭州市| 莱芜市| 大名县| 景谷| 松滋市| 突泉县| 临泉县| 广宁县| 静宁县| 册亨县| 高碑店市| 宝应县| 霍山县| 凯里市| 湖南省| 凌云县| 郴州市| 宁阳县| 克东县| 武威市| 江安县| 淮阳县| 兴和县| 日喀则市| 炉霍县| 南京市| 大姚县| 乡宁县| 保靖县| 阳原县| 东明县| 察雅县| 互助| 敦化市| 吉隆县| 青海省| 板桥市| 二手房| 清徐县| 古交市|