tomcat5.5下配置数据源,举例数据库为mysql

可以用http://localhost:8080/admin来配置,这里先不说这个(因为先前编辑了半天结果没发表成功,估计是用了n多图片的关系)

现在在context名为quickstart配置数据源 ,目录为%tomcat_home/webapps/quickstart,quickstart下新建目录META-INF,META-INF下面新建context.xml,内容如下

<?xml version="1.0" encoding="UTF-8"?>
<Context
    reloadable="true">
  <Resource
    auth="Container"
    description="mysql Connection"
    name="jdbc/quickstart"
    type="javax.sql.DataSource"
    driverClassName="com.mysql.jdbc.Driver"
    password="hib"
    maxIdle="2"
    maxWait="5000"
    username="hib"
    url="jdbc:mysql://127.0.0.1:3306/quickstart?useUnicode=true&amp;characterEncoding=GB2312"
    maxActive="4"/>
  <WatchedResource>e:/Program Files/Tomcat 5.5/conf/context.xml</WatchedResource>
  <WatchedResource>e:/Program Files/Tomcat 5.5/conf/context.xml</WatchedResource>
  <WatchedResource>e:/Program Files/Tomcat 5.5/conf/context.xml</WatchedResource>
</Context>

”<WatchedResource>“是我用admin新建context自动产生quickstart.xml时自动添加的。

quickstart下新建目录WEB-INF,在WEB-INF下新建web.xml,内容如下:

<?xml version="1.0" encoding="GB2312"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">
  <display-name>quickstart实验</display-name>
  <description>quickstart实验</description>
  <!--引用资源说明  引用资源的JNDI名   引用资源的类名  管理者(Container)--> 
   <resource-ref>
    <description>mysql Connection</description> 
    <res-ref-name>jdbc/quickstart</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>  
    <res-auth>Container</res-auth>          
   </resource-ref>


   <!-- default page 
 <welcome-file-list>
        <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>   -->
</web-app>

当然千万别忘了下载mysql-connector-java-5.0.0-beta-bin.jar,或者其他的版本也可以啊

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值