在Tomcat中配置資料來源(一共3個地方).

來源:互聯網
上載者:User

在Tomcat下配置資料來源真的煩瑣~``不過終於解決了,呼呼.....
現把配置方法貼在下面~~大家互相交流學習~~

環境:j2sdk-1_4_1_07  + tomcat-5.0.28 + windows XP + mysql

1,檔案位置:%TOMCAT_HOME%/conf/server.xml

在<GlobalNamingResources>地區添加
    <Resource type="javax.sql.DataSource" name="jdbc/test"/>
    <ResourceParams name="jdbc/myds">
      <parameter>
        <name>url</name><value>jdbc:mysql://localhost:3306/mydb</value>
      </parameter>
      <parameter>
        <name>password</name><value></value>
      </parameter>
      <parameter>
        <name>maxActive</name><value>4</value>
      </parameter>
      <parameter>
        <name>maxWait</name><value>5000</value>
      </parameter>
      <parameter>
        <name>driverClassName</name><value>org.gjt.mm.mysql.Driver</value>
      </parameter>
      <parameter>
        <name>username</name><value>root</value>
      </parameter>
      <parameter>
        <name>maxIdle</name><value>2</value>
      </parameter>
    </ResourceParams>

 

2,%TOMCAT_HOME%/conf/Catalina/localhost/[yourWebAppName].xml

在<Context>地區添加
<ResourceLink name="jdbc/test" type="javax.sql.DataSource" global="jdbc/test"/>

 

3,%yourWebAppHome%/WEB-INF/web.xml

在<web-app>地區添加
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/test</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.