首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

Tomcat 六 数据源配置

2012-10-25 
Tomcat 6 数据源配置I.?%Tomcat_Home%\conf\ 下面的context.xml 在Context中加入下面的代码?Resource n

Tomcat 6 数据源配置

I.

?

%Tomcat_Home%\conf\ 下面的context.xml 在<Context>中加入下面的代码

?

<Resource name="jdbc/oracle" auth="Container" type="javax.sql.DataSource" maxActive="10" maxIdle="10" maxWait="1000" username="scott" password="tiger" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:ORCL"/>

?

?

II.

?

编辑项目下的web.xml文件,在<web-app>中加入下面的代码

?

<resource-ref>
???? <description>Tomcat Data Source</description>
???? <res-ref-name>jdbc/oracle</res-ref-name>
???? <res-type>javax.sql.DataSource</res-type>
???? <res-auth>Container</res-auth>
?</resource-ref>

?

III.

?

建一个servlet测试一下:

?

 Connection conn = null;   try    {        Context initContext = new InitialContext();        Context envContext = (Context)initContext.lookup("java:/comp/env");        DataSource ds = (DataSource)envContext.lookup("jdbc/oracle");        conn = ds.getConnection();   if(conn != null)   {  out.println("Tomcat数据源连接成功!");  } } catch(Exception e) {   e.printStackTrace(); }

?

热点排行