[求助]JSP連線SQL Server 2000問題,看了很多資料還未解決,求救!

langfanyun11發表於2006-03-24
本機環境: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

相關文章