我的连接池使用出现错误

bobytiger 2005-06-04 11:39:54
刚学jsp,树上有这样的程序:但运行后结果不正确!请高手指教!!!谢谢先!!
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,javax.naming.*,javax.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>连接池连接MS SQL Server 2000</title>
</head>
<body>
<%
out.print("使用连接池连接MS SQL Server 2000<br>");
out.println("<br>");
Context ctx=null;
DataSource ds=null;
Statement stmt=null;
ResultSet rs=null;
Connection con=null;
ResultSetMetaData md=null;
try{
ctx = new InitialContext();
ds = (DataSource)ctx.lookup("java:comp/env/jdbc/firm");
con=ds.getConnection();
stmt=con.createStatement();
rs=stmt.executeQuery("select * from user");
md=rs.getMetaData();
out.print(md.getColumnLabel(1)+" ");
out.print(md.getColumnLabel(2)+"<br>");
while(rs.next()){
out.print(rs.getInt(1)+" ");
out.print(rs.getString(2)+"<br>");
}
}catch(Exception e){
out.print(e);
}finally{
if(rs!=null)rs.close();
if(stmt!=null)stmt.close();
if(con!=null)con.close();
}
%>
</body>
</html>

结果显示如下:
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
不知是什么问题?
...全文
89 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
guo__peng 2005-06-13
  • 打赏
  • 举报
回复
JNDI没设对,或是连接池没配好
jolestar 2005-06-13
  • 打赏
  • 举报
回复
你的jndi设对了没?
naxin 2005-06-13
  • 打赏
  • 举报
回复
如果用的tomcat , 请参看tomcat的帮助中jndi的相关例子.
侠之大者 f 2005-06-13
  • 打赏
  • 举报
回复
555,我的错误信息跟你一样,不知道是怎么回事了!

81,092

社区成员

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

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