[求助]JSP连接SQL Server 2000问题,看了很多资料还未解决,求救!

06-03-24 langfanyun11
本机环境:WinXP +SP2 JDK1.5.0 Tomcat5.0.16 SQL Server 2000(XP下能用的那种版本)

已装了SQL Server 2000 Driver for JDBC Service Pack 3,并且已经把msbase.jar,mssqlserver.jar,msutil.jar拷贝到Tomcat目录下common\lib目录下,之后,修改环境变量中的CLASSPATH,
把SQL Server 2000 For JDBC 驱动程序安装目录下的
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;
追加到CLASSPATH中去。

JDK和Tomcat 测试后都能正常运行,JavaBean,Servlet都测试能正常运行。

用于测试连接数据库的代码如下:
<%-- 使用JDBC驱动直接访问SQLServer2000数据库. --%>

<%@ page contentType = "text/html; charset = gb2312" language = "java" import = "java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >

<html>
<head>
<title>
use JDBC to connect SQL Server
</title>

<style type = "text/css">
<!--
.style{
color:FF0000;
font-size:24px;
}
-->
</style>
</head>

<body>
<div align = "center" ><span class = "style1" > JDBC access SQL Server directly </span><BR></div>
<hr><br>
<table border = 2 bordercolor = "FF0000" align = "center">
<tr>
<td> au_id </td>
<td> au_lname </td>
<td> au_fname </td>
<td> phone </td>
<td> address </td>
<td> city </td>
<td> state </td>
<td> zip </td>
<td> contract </td>
<tr>

<%
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" ).newInstance();
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName = pubs";
String user = "yc";
String password = "123";
Connection conn = DriverManager.getConnection( url, user, password );
Statement stmt = conn.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE );
String sql = "SELECT TOP 10 * FROM authors";
ResultSet rs = stmt.executeQuery( sql );

while( rs.next() ){
%>

<tr>
<td><%= rs.getString( "au_id" ) %></td>
<td><%= rs.getString( "au_lname" ) %></td>
<td><%= rs.getString( "au_fname" ) %></td>
<td><%= rs.getString( "phone" ) %></td>
<td><%= rs.getString( "address" ) %></td>
<td><%= rs.getString( "city" ) %></td>
<td><%= rs.getString( "state" ) %></td>
<td><%= rs.getString( "zip" ) %></td>
<td><%= rs.getString( "contract" ) %>
</tr>

<%}%>
<%
out.print( "Congratulations, The access is successful!" );
rs.close();
stmt.close();
conn.close();
%>
</table>
</body>
</html>
(该程序在其他机器上运行后能连上数据库)

JSP页面提示错误信息为:
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.test.E6_jsp._jspService(E6_jsp.java:87)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSConnection.(Unknown Source)
com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.test.E6_jsp._jspService(E6_jsp.java:47)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.16

yxb335
2006-03-24 15:33
我也遇到这样的问题,实在没有办法,就用JDBC-OBDC吧!

jasher2006
2006-03-24 17:38
好像是你数据库的问题,重新换一台可以使用的数据库的机器

lijinlinlin
2006-03-24 20:29
这个问题我遇到过!!!

经过反复尝试,得出如下结论:
由于XP、WIN2000 Pro等WINDOWS版本只能安装SQLSERVER个人版或企业测试版,而连接池是无法在这些SQLSERVER版本上使用的。

同样的程序,我换到WIN2000 Server、SQLSERVER2000企业版上一点问题都没有。即便是WIN2000 Server、SQLSERVER2000标准版这样的环境也是不行的。

只有SQLSERVER2000企业版才能配置成功。

pbabi
2006-03-24 21:25
我用的是WIN2000+TOMCAT不起5.0.28+JDK1.4.2 +SQL SERVER2000标准版,用的也是SQL Server 2000 Driver for JDBC Service Pack 3,也可以连上