ホームページ  >  記事  >  データベース  >  配置MySQL数据源在tomcat5中

配置MySQL数据源在tomcat5中

WBOY
WBOYオリジナル
2016-06-07 16:11:42897ブラウズ

以下的文章主要讲述的是如何在tomcat5中正确配置MySQL数据源,以下的文章我们主要是对tomcat5中正确配置MySQL数据源的实际操作步骤的详细介绍,以下就是文章的具体操作步骤描述。 一、配置MySQL环境变量: softe version:tomcat(一个很好用的JSP运行平台)5.0

以下的文章主要讲述的是如何在tomcat5中正确配置MySQL数据源,以下的文章我们主要是对tomcat5中正确配置MySQL数据源的实际操作步骤的详细介绍,以下就是文章的具体操作步骤描述。

 一、配置MySQL环境变量:

softe version:tomcat(一个很好用的JSP运行平台)5.0.12/MySQL(和PHP搭配之最佳组合)4.1.7/MySQL(和PHP搭配之最佳组合)_driver---

MySQL(和PHP搭配之最佳组合)-connector-java-3.1.4-beta-bin.jar

MySQL(和PHP搭配之最佳组合)驱动程序可从www.MySQL(和PHP搭配之最佳组合).com官方网站下载

路径:

tomcat(一个很好用的JSP运行平台)5在d:mywebomcat5;

MySQL(和PHP搭配之最佳组合)在C:Program FilesMySQL(和PHP搭配之最佳组合)MySQL(和PHP搭配之最佳组合) Server 4.1

Path(在原来的基础上加上):

<ol class="dp-xml">
<li class="alt"><span><span>d:mywebomcat5in;d:mywebjdk1.4;d:myweb  </span></span></li>
<li><span>jdk1.4in;  </span></li>
<li class="alt"><span>d:mywebomcat5commonlibservlet-api.jar;C:Program Files  </span></li>
<li>MySQL<span>(和PHP搭配之最佳组合)</span>MySQL<span>(和PHP搭配之最佳组合) Server4.1in  </span>
</li>
<li class="alt"><span>CLASSPATH:d:mywebomcat5commonlibservlet-api.jar;d:myweb  </span></li>
<li><span>tomcat(一个很好用的JSP运行平台)5commonlibjsp(SUN企业级应用的首选)-api.jar  </span></li>
<li class="alt"><span>JAVA_HOME:d:mywebjdk1.4  </span></li>
<li><span>CATALINA_HOME:d:mywebomcat5 </span></li>
</ol>

二、建立测试数据库

在MySQL(和PHP搭配之最佳组合)中建立一个forumdb数据库,同时创建一个表member如下:

<ol class="dp-xml">
<li class="alt"><span><span>create database forumdb;  </span></span></li>
<li><span>create table member  </span></li>
<li class="alt"><span>(  </span></li>
<li><span>id int,  </span></li>
<li class="alt"><span>name varchar(6)  </span></li>
<li><span>); </span></li>
</ol>

然后插入两条测试数据如下:

<ol class="dp-xml">
<li class="alt"><span><span>insert into member values(1,"zhang");  </span></span></li>
<li><span>insert into member values(2,"wang"); </span></li>
</ol>

至此,数据库准备完毕。

三、配置server.xml(标准化越来越近了)

注:我的web在d:mywebmyapps

首先要将MySQL(和PHP搭配之最佳组合)的驱动程序放到d:mywebomcat5commonlib下面,一定要放".jar"的文件,如是".zip"的文件直接改为.jar即可。

用文本编辑器打开D:omcat5confserver.xml(标准化越来越近了),找到结束标志,然后在之前加上如下语句:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span class="tag-name">Context</span><span> </span><span class="attribute">path</span><span>=</span><span class="attribute-value">"/myapps"</span><span> </span><span class="attribute">docBase</span><span>=</span><span class="attribute-value">"d:mywebmyapps"</span><span> </span><span class="attribute">debug</span><span>=</span><span class="attribute-value">"0"</span><span> </span></span></span></li>
<li>
<span class="attribute">reloadable</span><span>=</span><span class="attribute-value">"true"</span><span> </span><span class="tag">></span><span> </span>
</li>
<li class="alt"><span class="tag"><span class="tag-name">Resource</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"jdbc/DBConnection"</span><span> </span></span></li>
<li>
<span class="attribute">auth</span><span>=</span><span class="attribute-value">"Container"</span><span> </span>
</li>
<li class="alt">
<span class="attribute">type</span><span>=</span><span class="attribute-value">"javax.sql.DataSource"</span><span> </span><span class="tag">/></span><span> </span>
</li>
<li><span class="tag"><span class="tag-name">ResourceParams</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"jdbc/DBConnection"</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span class="tag-name">parameter</span><span class="tag">></span><span> </span></span></li>
<li><span class="tag"><span class="tag-name">name</span><span class="tag">></span><span>factory</span><span class="tag"></span><span class="tag-name">name</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span class="tag-name">value</span><span class="tag">></span><span>org.apache(Unix平台最流行的WEB服务器平台).commons.dbcp.BasicDataSourceFactory</span><span class="tag"></span><span class="tag-name">value</span><span class="tag">></span><span> </span></span></li>
<li>
<span class="tag"></span><span class="tag-name">parameter</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span><!-- Maximum number of dB connections in pool. Make sure you  </span></li><li><span> configure your </span>MySQL<span>(和PHP搭配之最佳组合)d max_connections large enough to handle  </span></li><li class="alt"><span> all of your db connections. Set to 0 for no limit.  </span></li><li><span> --</span><span class="tag">></span><span> </span></li><li class="alt"><span class="tag"><</span><span class="tag-name">parameter</span><span class="tag">></span><span> </span></li><li><span class="tag"><</span><span class="tag-name">name</span><span class="tag">></span><span>maxActive</span><span class="tag"></</span><span class="tag-name">name</span><span class="tag">></span><span> </span></li><li class="alt"><span class="tag"><</span><span class="tag-name">value</span><span class="tag">></span><span>10</span><span class="tag"></</span><span class="tag-name">value</span><span class="tag">></span><span> </span></li><li><span class="tag"></</span><span class="tag-name">parameter</span><span class="tag">></span><span> </span></li><li class="alt"><span><!-- Maximum number of idle dB connections to retain in pool.  </span></li><li><span> Set to 0 for no limit.  </span></li><li class="alt"><span> --</span><span class="tag">></span><span> </span></li><li><span class="tag"><</span><span class="tag-name">parameter</span><span class="tag">></span><span> </span></li><li class="alt"><span class="tag"><</span><span class="tag-name">name</span><span class="tag">></span><span>maxIdle</span><span class="tag"></</span><span class="tag-name">name</span><span class="tag">></span><span> </span></li><li><span class="tag"><</span><span class="tag-name">value</span><span class="tag">></span><span>3</span><span class="tag"></</span><span class="tag-name">value</span><span class="tag">></span><span> </span></li><li class="alt"><span class="tag"></</span><span class="tag-name">parameter</span><span class="tag">></span><span> </span></li><li><span><!-- Maximum time to wait for a dB connection to become available  </span></li><li class="alt"><span> in ms, in this example 10 seconds. An Exception is thrown if  </span></li><li><span> this timeout is exceeded.Set to -1 to wait indefinitely.  </span></li><li class="alt"><span>Maximum time to wait for a dB connection to become available  </span></li><li><span> in ms, in this example 10 seconds. An Exception is thrown if  </span></li><li class="alt"><span> this timeout is exceeded.Set to -1 to wait indefinitely.  </span></li><li><span> --</span><span class="tag">></span><span> </span></li><li class="alt"><span class="tag"><</span><span class="tag-name">parameter</span><span class="tag">></span><span> </span></li><li><span class="tag"><</span><span class="tag-name">name</span><span class="tag">></span><span>maxWait</span><span class="tag"></</span><span class="tag-name">name</span><span class="tag">></span><span> </span></li><li class="alt"><span class="tag"><</span><span class="tag-name">value</span><span class="tag">></span><span>10000</span><span class="tag"></</span><span class="tag-name">value</span><span class="tag">></span><span> </span></li><li><span class="tag"></</span><span class="tag-name">parameter</span><span class="tag">></span><span> </span></li><li class="alt"><span class="comments"><!-- MySQL(和PHP搭配之最佳组合) dB username and password for dB connections--></span><span> </span>
</li>
<li><span class="tag"><span class="tag-name">parameter</span><span class="tag">></span><span> </span></span></li>
<li class="alt">
<span> </span><span class="tag"><span class="tag-name">name</span><span class="tag">></span><span>username</span><span class="tag"></span><span class="tag-name">name</span><span class="tag">></span><span> </span></span>
</li>
<li>
<span> </span><span class="tag"><span class="tag-name">value</span><span class="tag">></span><span>root</span><span class="tag"></span><span class="tag-name">value</span><span class="tag">></span><span> </span></span>
</li>
<li class="alt">
<span class="tag"></span><span class="tag-name">parameter</span><span class="tag">></span><span> </span>
</li>
<li><span class="tag"><span class="tag-name">parameter</span><span class="tag">></span><span> </span></span></li>
<li class="alt">
<span> </span><span class="tag"><span class="tag-name">name</span><span class="tag">></span><span>password</span><span class="tag"></span><span class="tag-name">name</span><span class="tag">></span><span> </span></span>
</li>
<li>
<span> </span><span class="tag"><span class="tag-name">value</span><span class="tag">></span><span>1234</span><span class="tag"></span><span class="tag-name">value</span><span class="tag">></span><span> </span></span>
</li>
<li class="alt">
<span class="tag"></span><span class="tag-name">parameter</span><span class="tag">></span><span> </span>
</li>
<li>
<span class="comments"><!-- Class name for mm.MySQL(和PHP搭配之最佳组合) JDBC driver --></span><span> </span>
</li>
<li class="alt"><span class="tag"><span class="tag-name">parameter</span><span class="tag">></span><span> </span></span></li>
<li>
<span> </span><span class="tag"><span class="tag-name">name</span><span class="tag">></span><span>driverClassName</span><span class="tag"></span><span class="tag-name">name</span><span class="tag">></span><span> </span></span>
</li>
<li class="alt">
<span> </span><span class="tag"><span class="tag-name">value</span><span class="tag">></span><span>com.</span>MySQL<span>(和PHP搭配之最佳组合).jdbc.Driver</span><span class="tag"></span><span class="tag-name">value</span><span class="tag">></span><span> </span></span>
</li>
<li>
<span class="tag"></span><span class="tag-name">parameter</span><span class="tag">></span><span> </span>
</li>
<li class="alt"><span></span></li>
</ol>
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。