在网页中显示的错误为:Name jdbc is not bound in this Context

ButterFly0513 ButterFly0513 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在网页中显示的错误为:Name jdbc is not bound in this Context

代码如下:
<%@page import="java.io.*" %>
<%@page import="java.util.*" %>
<%@page import="java.sql.*" %>
<%@page import="javax.sql.*" %>
<%@page import="javax.naming.*" %>


<html>
<head>
<title>accessDataSource</title>
</head>
<body>
<%
try{
Connection con;
Statement stmt;
ResultSet rs;


Context ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/text");


con=ds.getConnection();

stmt=con.createStatement();
stmt.executeUpdate("insert into BOOKS(ID,NAME,TITLE,PRICE) values ('555','555','555',44.5)");

rs=stmt.executeQuery("select ID,NAME,TITLE,PERICE from BOOKS");

out.println("<table border=1 width=400>");
while(rs.next()){
String col1=rs.getString(1);
String col2=rs.getString(2);
String col3=rs.getString(3);
float col4=rs.getFloat(4);

col1=new String(col1.getBytes("ISO-8859-1"),"GB2312");
col2=new String(col2.getBytes("ISO-8859-1"),"GB2312");
col3=new String(col3.getBytes("ISO-8859-1"),"GB2312");

out.println("<tr><td>"+col1+"</td><td>"+col2+"</td><td>"+col3+"</td><td>"+col4+"</td></tr>");

}
out.println("</table>");

stmt.executeUpdate("delete from BOOKS where ID='555'");

rs.close();
stmt.close();
con.close();
}catch (Exception ee){
out.println(ee.getMessage());ee.printStackTrace();
}
%>
</body>
</html>


在web.xml中代码如下:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/text</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
在context.xml中代码如下:
<Context reloadable="true">
<Resource name="jdbc/text" auth="Container" tyep="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="text" password="text"
dricerClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:orcl"
/>

</Context>

Myeclipse显示:javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
请高手指教是什么问题,多谢了
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
ButterFly0513
Web 开发 81,108 成员 341,721 内容