weblogic10.3 javax.naming.NameNotFoundException:

weblogic10.3配制好数据源后
小例子连接数据库jsp页面:
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
       <link rel="stylesheet" type="text/css" href="styles.css">
       -->
</head>

<body>
This is my JSP page.
<br>
</body>
<%
try {
Context envContext = (Context) new InitialContext();
DataSource ds = (DataSource) envContext.lookup("orcl1"); //查找配置orcl1为jndi名字
Connection conn = ds.getConnection();
Statement st = conn.createStatement();
  st.execute("insert into auyh(yhid,yhm) values(1223,'李峰')");

ResultSet rs = st.executeQuery("select * from auyh");
while (rs.next()) {
out.println(rs.getString("yhm") + "<br>");
}
} catch (NamingException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
%>


</html>

出现异常如下:

<2010-12-7 下午05时59分11秒 CST> <Warning> <Common> <BEA-000632> <Resource Pool "orcl1" shutting down, ignoring 1 resources still in use by applications..>
javax.naming.NameNotFoundException: Unable to resolve 'orcl1'. Resolved ''; remaining name 'orcl1'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:252)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:182)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:206)
at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:388)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at jsp_servlet.__index._jspService(__index.java:99)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3590)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2200)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2106)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1428)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)



解决办法:
在weblogic配制数据源时,
选中 见图

你可能感兴趣的:(java,sql,jsp,servlet,weblogic)