javax.naming.NameNotFoundException: Unable to resolve 'jdbc.mydb'. Resolved 'jdbc'; remaining name '

时间:2023-01-19 22:03:43

WebLogic中JNDI遇到的非常非常小的问题:

错误如下:

javax.naming.NameNotFoundException: Unable to resolve 'jdbc.mydb'. Resolved 'jdbc'; remaining name 'mydb'
	at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1180)
	at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:270)
	at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:187)
	at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:210)
	at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:224)
	at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:253)
	at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:426)
	at javax.naming.InitialContext.lookup(InitialContext.java:411)
	at jsp_servlet.__index._jspService(__index.java:101)
	at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
	at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
	at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
	at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
	at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:341)
	at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:238)
	at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3363)
	at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3333)
	at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
	at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
	at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
	at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2220)
	at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2146)
	at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2124)
	at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1564)
	at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
	at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
	at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)


代码连接如下:

DataSource ds = (DataSource)ctx.lookup(“jdbc.mydb”);



出现这个是由于没有找到JNDI,(其实是废话,报错已经说明了 ^_^);

解决方法:

在Weblogic数据源管理中的

JDBC Data Source-0的设置

中设置目标选项

将服务勾选上,如默认的:AdminServer
保存后即可;