tomcat5.0+sql Name sqlserver is not bound in this Context,查了好多资料都不行,大家帮帮忙啊!!!急!!急!!!
我用tomcat图形上面配置连接池
配置信息如下:
JNDI Name: jdbc/sqlserver
Data Source URL: jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=CyxtExploristjdbc:microsoft:sqlserver://localhost:1433;DatabaseName=CyxtExplorist
JDBC Driver Class: com.microsoft.jdbc.sqlserver.SQLServerDriver
User Name: sa
Password: sa
Max. Active Connections: 4
Max. Idle Connections: 2
Max. Wait for Connection: 5000
点击save再点击commit changes 后自动在localhost下生成一些配置文件但在JSP文件测试时出现Name sqlserver is not bound in this Context的错误。
JSP代码:
<%@ page contentType= "text/html; charset=gb2312 " language= "java "
errorPage= " " %>
<%@ page import= "java.sql.* "%>
<%@ page import= "javax.sql.* "%>
<%@ page import= "javax.naming.* "%>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 通过Tomcat连接池连接SQL Server数据库 </title>
<style type= "text/css ">
<!--
.style1 {color: #0000FF}
-->
</style>
</head>
<body>
<div align= 'center '>
<span class= "style1 ">
<%
DataSource ds = null;
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try{
InitialContext ctx=new InitialContext();
ds=(DataSource)ctx.lookup( "java:comp/env/jdbc/sqlserver ");
conn = ds.getConnection();
}
catch(Exception e){
e.printStackTrace();
}
%>
<%if(conn!=null){
try{
stmt=conn.createStatement();
rs=stmt.executeQuery( "select * from stu ");
%>
取得数据库连接成功!!! </span>
<table width= "220 " border= "1 ">
<tr align= "center ">
<td> <span class= "style1 "> 姓名 </span> </td>
<td> <span class= "style1 "> 年龄 </span> </td>
<td> <span class= "style1 "> 职业 </span> </td>
</tr>
<%while(rs.next()){
System.out.println(rs.getInt(1));
System.out.println();
%>
</tr>
<%
}
System.out.println();
%>
</table>
<%
}catch(Exception e){
}%>
<%}%>
</body>
</html>
请指教解决方案????急!在