新手问题:Eclipse连接mysql出现的问题

jackymann 2006-12-22 06:48:57
用Eclipse连接mysql数据库,在浏览器中运行时出现下列错误提示:Name jdbc is not bound in this Context。这是什么意思啊?我是新手,请大家帮忙看一下,谢谢了。
Eclipse:3.0.1
mysql:5.0.27
jdbc:mysql-connector-java-5.0.3
具体代码:

test.jsp
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%
out.println("first");
Connection con=null;
Statement sm=null;
ResultSet rs=null;
try
{

InitialContext ctx=new InitialContext();

DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");

con=ds.getConnection();
sm=con.createStatement();
rs=sm.executeQuery("select UserName from userinfo");
while(rs.next())
out.println(rs.getString("UserName")+".");

}
catch(Exception e)
{
e.printStackTrace();out.println("second");
out.println(e.getMessage());
}
finally
{
if(rs!=null)
{
try
{
rs.close();
}
catch(SQLException e)
{}
rs=null;
}
if(sm!=null)
{
try
{
sm.close();
}
catch(SQLException e)
{}
sm=null;
}
if(con!=null)
{
try
{
con.close();
}
catch(SQLException e)
{}
con=null;
}
}
%>
...全文
210 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
松耦合紧内聚 2006-12-22
  • 打赏
  • 举报
回复
servlet容器[for example tomcat or resin]的配置文件中没有声明此连接池!

58,454

社区成员

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

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