如何访问weblogic 10.3.6中定义的JNDI数据源 [英] How to access JNDI data source defined in weblogic 10.3.6

查看:652
本文介绍了如何访问weblogic 10.3.6中定义的JNDI数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用我的weblogic控制台创建了一个JNDI数据源,但是我无法从我的Web应用程序访问该对象。以下是详细信息

I have created a JNDI data-source using my weblogic console but I am not able to access the object from my web application. Below are the details

在weblogic 10.3.6中,我已将数据源的JNDI名称指定为: jdbc / mydb

In weblogic 10.3.6, I have given the JNDI name for datasource as : jdbc/mydb

要从我的网络应用程序获取数据库连接,我已在我的网络应用程序中编写此代码:

To get DB connection from my web application I have written this code in my web application:

Context initContext = new InitialContext();
DataSource ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/mydb");
jndiConnection = ds.getConnection();

之前我使用Tomcat作为服务器,当我配置资源详细信息时,我能够获得数据库连接在文件 tomcat / conf / server.xml 中,但当我使用weblogic服务器时,我收到以下错误:

Earlier I was using Tomcat as server and I was able to get DB connection when I configured the resource details in the file tomcat/conf/server.xml, but when I am using started using weblogic server I am getting below error:

Cannot establish DB connection to JNDI:java:/comp/env/jdbc/mydb While trying to look up /comp/env/jdbc/mydb in /app/webapp/sample.war/1811641702. caused by: javax.naming.NameNotFoundException: While trying to look up /comp/env/jdbc/mydb in /app/webapp/sample.war/1811641702.; remaining name '/comp/env/jdbc/mydb'

我已尝试过此链接中提到的选项:如何在WebLogic上查找JNDI资源?但我仍然面临着问题。

I have tried the options mentioned in this link : How to lookup JNDI resources on WebLogic? but still I am facing problems.

请让我知道我在哪里做错了,访问JNDI对象的过程是什么。

Please let me know where I am doing mistake, what is the process of accessing the JNDI object.

推荐答案

在参考帖子后: Tomcat vs Weblogic JNDI Lookup 我修改了我的代码。

After referring to the post:Tomcat vs Weblogic JNDI Lookup I have modified my code.

在我的Web应用程序的java程序中使用下面的代码解决了我的问题:

Using below code in my java program of web application has solved my issue:

Context initContext = new InitialContext();
DataSource ds = (DataSource)initContext.lookup("jdbc/mydb");
jndiConnection = ds.getConnection();

同样在weblogic控制台中我将我的JNDI对象添加到我的管理服务器(在服务器选项下)部署了Web应用程序。

Also in weblogic console I have added my JNDI object to my Admin Server (under servers option) where my web application is deployed.

这篇关于如何访问weblogic 10.3.6中定义的JNDI数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆