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

ButterFly0513 2010-10-25 09:05:58
在网页中显示的错误为: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
请高手指教是什么问题,多谢了
...全文
194 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
magong 2010-10-25
  • 打赏
  • 举报
回复
没必要重复发帖,加分就行了,别人自然会注意的。
那边答了,这里不重复了

http://topic.csdn.net/u/20101025/08/794cdef7-8d6c-4907-a541-f151c9efa540.html
ButterFly0513 2010-10-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hack_ccsl 的回复:]
在web.xml中配置如下:
<resource-ref>
<res-ref-name>数据库名</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resour……
[/Quote]

还是不能解决问题的
ButterFly0513 2010-10-25
  • 打赏
  • 举报
回复
[Quote=引用楼主 butterfly0513 的回复:]
在网页中显示的错误为: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 i……
[/Quote]


还是不能解决问题
hack_ccsl 2010-10-25
  • 打赏
  • 举报
回复
在web.xml中配置如下:
<resource-ref>
<res-ref-name>数据库名</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
在tomcat中配置如下:
<Context path="/web的根目录名">
<Resource name="数据库名"
type="javax.sql.DataSource"
username="root"
password="root"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="10"
url="jdbc:mysql://localhost:3306/tarena"
maxActive="10"/>
</Context>

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧