在网页中显示的错误为:Name jdbc is not bound in this Context
在网页中显示的错误为: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
请高手指教是什么问题,多谢了