Tomcat上配置连接池{ connect error=Name [jdbc/OracleDB] is not bound in this Context. Unable to find [jdbc]

java

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

public static Connection getConnection_tomcat() {

       Connection conn = null;

       try {

           Context initCtx = new InitialContext();

           Context ctx = (Context) initCtx.lookup("java:comp/env");



           Object obj = (Object) ctx.lookup("jdbc/OracleDB");

           javax.sql.DataSource ds = (javax.sql.DataSource) obj;

           return conn = ds.getConnection();

       }

       catch (Exception e) {



           System.out.println("connect error=" + e.getMessage());

           return null;

       }

   } 

在tomcat->conf->server.xml

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

<!-- Editable user database that can also be used by

     UserDatabaseRealm to authenticate users

-->

<Resource name="UserDatabase" auth="Container"

          type="org.apache.catalina.UserDatabase"

          description="User database that can be updated and saved"

          factory="org.apache.catalina.users.MemoryUserDatabaseFactory"

          pathname="conf/tomcat-users.xml" />
<Resource name="jdbc/OracleDB"  auth="Container"          

          type="javax.sql.DataSource" 

          driverClassName="oracle.jdbc.driver.OracleDriver"   

          url="" 

          maxActive="50"   

          maxldle="10"   

          maxWait="5000" 

          username="" 

          password="" />  

在tomcat->conf->context.xml 

1

2

3

4

5

6

7

8

<WatchedResource>WEB-INF/web.xml</WatchedResource>





<!-- 配置一个连接池 如果数据库的连接就是在tomcat->conf->context.xml ,则不需要此步-->

<ResourceLink global="jdbc/OracleDB" name="jdbc/OracleDB" type="javax.sql.DataSource"/>  

这样就大功告成了! 本人从其他博客摘抄,以便回顾。 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值