Name jdbc is not bound in this Context

Name jdbc is not bound in this Context

题目
Name jdbc is not bound in this Context
tomcat的conf\catalina\localhost配置samples.xml
eclipse的samples工程里名为ConnPool的servlet
package servlet;
import java.sql.*;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class ConnPool
*/
public class ConnPool extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
response.setCharacterEncoding("GB2312");
PrintWriter out=response.getWriter();
try
{
javax.naming.Context ctx=new javax.naming.InitialContext();
javax.sql.DataSource ds=(javax.sql.DataSource) ctx.lookup("java:/comp/env/jdbc/jdbcdemo");
Connection conn=ds.getConnection();
PreparedStatement pstmt=conn.prepareStatement("select * from t_books");
ResultSet rs=pstmt.executeQuery();
StringBuilder table=new StringBuilder();
table.append("");
table.append("");
while(rs.next())
{
table.append("");
}
table.append("
书名作者
"+rs.getString("name")+"");
table.append(rs.getString("author")+"
");
out.println(table.toString());
pstmt.close();
}
catch(Exception e)
{
out.println(e.getMessage());
}
out.flush();
out.close();
}
}.
为什么会这样呢?
答案
在web.xml中配置如下:<resource-ref><res-ref-name>数据库名</res-ref-name><res-type>javax.sql.DataSource</res-type><res-auth>Container</res-auth>{...
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
热门考点

超级试练试题库

© 2017-2019 超级试练试题库,All Rights Reserved.