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 + "/";
%>






My JSP 'index.jsp' starting page









This is my JSP page.



<%
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") + "
");
}
} catch (NamingException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
%>




出现异常如下:

<2010-12-7 下午05时59分11秒 CST>
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,Weblogic,Java,Servlet,JSP,SQL)