javax.naming.NameNotFoundException:名称jdbc未绑定在此Context中

时间:2011-06-24 12:57:52

标签: web-services jdbc error-handling tomcat6

我在网络服务上工作......我是初学者, 我试图在服务文件中获得Oracle Db连接并且我遇到错误:

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
    at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    at DatabaseConnection.shamDBConn.getShamStage(shamDBConn.java:25)
    at lineItemPrice.itemDetails.getUserId(itemDetails.java:17)
    at ServerSevices.availableServices.useridService(availableServices.java:11)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:194)
    at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:102)
    at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
    at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:100)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:176)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:133)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)

在Apache Tomcat 6.0.32中使用Oracle 10g进行数据库配置的链接如下所示

http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html

我已经进行了如下设置: enter image description here

我在下面的行中收到错误:

DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");

我错过了什么......?

谢谢.........

3 个答案:

答案 0 :(得分:11)

您的问题是您需要在jndi字符串前加上java:/ comp / env

所以在你的情况下试试:

DataSource ds = (DataSource)envContext.lookup("java:/comp/env/jdbc/myoracle");

那应该可以解决问题。

答案 1 :(得分:0)

我也遇到过这个问题,但在我的情况下我通过添加下面的行来修复:

<ResourceLink global="jdbc/myoracle" name="jdbc/myoracle" type="oracle.jdbc.pool.OracleDataSource"/>

到tomcat conf文件 - &gt; context.xml

答案 2 :(得分:0)

尝试“ java:”

(DataSource) context.lookup("java:jdbc/myoracle");