ITeye博客

存一个最简单的配置Tomcat数据源的方式

秀才的梦想 · 2009-05-23 01:23 · 关于技术 · Markdown

这两天做东西想配个数据源,因为是在基本类中使用数据源,Struts配置的数据源无法使用,所以想找个简单点的数据源配置方式(只用到了一点数据库),找了很多这个算是最简单的了,总结了一下步骤,Easy,就是在项目的META-INF目录下建一个context.xml文件,对!就是和Tomcat/conf下的context.xml一样的文件,内容也是一样的,在里面配置数据源,省去了复制粘贴的麻烦,可以走到哪里带到哪里,老少皆宜,配置方式和内容如下:地球人都知道,自己备着用来复制粘贴=。=

context.xml

<?xml version="1.0" encoding="GBK"?>   
<Context>
    <Resource name="jdbc/sqlserver"    
              type="javax.sql.DataSource"  
              driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"    
              maxIdle="2"    
              maxWait="5000"  
              username="sa"  
              password=""  
              url="jdbc:microsoft:sqlserver://localhost:1433"/>  
    <Resource name="jdbc/mysql"    
              type="javax.sql.DataSource"  
              driverClassName="com.mysql.jdbc.Driver"    
              maxIdle="2"    
              maxWait="5000"  
              username="root"  
              password="1234"  
              url="jdbc:mysql://localhost:3306/mysql"/>      
</Context>  

web.xml添加内容如下: 

<resource-ref>
	<description>DBConnection</description>
	<res-ref-name>jdbc/mysql</res-ref-name>
	<res-type>javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
	<description>DBConnection</description>
	<res-ref-name>jdbc/sqlserver</res-ref-name>
	<res-type>javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
</resource-ref>

用法就不用说了吧...JNDI...这个比较好搜索...

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。