`
loquat
  • 浏览: 68820 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

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();
 }

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics