JSP连接SQLServer2000出错,请求帮助
我的JSP代码如下:
<%@ page language= "java " contentType= "text/html; charset=GB18030 "
pageEncoding= "GB18030 "%>
<%@ page import= "java.sql.* "%>
<!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=GB18030 ">
<title> 学生成绩管理系统 </title>
</head>
<body bgcolor= "blue ">
<h3> 学生成绩管理系统 </h3>
<%
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=sgs ";
String username= "sa ";
String password= "123456 ";
Connection con=DriverManager.getConnection(url,username,password);
if(con==null)
{
%>
对不起数据库连接出错!
<%
}
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
%>
<table border=1 align=center>
<tr>
<td> 学生学号 </td> <td> 学生姓名 <td/> <td> 班级 <td/> <td> 专业 <td/>
</tr>
<%
String sql= "select * from student ";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
%>
<tr>
<td> <%=rs.getString( "学号 ") %> </td>
<td> <%=rs.getString( "姓名 ") %> </td>
<td> <%=rs.getString( "班级 ") %> </td>
<td> <%=rs.getString( "专业 ") %> </td>
</tr>
<%
}
rs.close();
stmt.close();
con.close();
//dbconn.releaseConnection(con);
%>
</table>
</body>
</html>
运行后的出错报告如下:
exception
org.apache.jasper.JasperException: Exception in JSP: /index.jsp:18
15: String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=sgs ";
16: String username= "sa ";
17: String password= "101210 ";
18: Connection con=DriverManager.getConnection(url,username,password);
19: if(con==null)
20: {
21: %>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.index_jsp._jspService(index_jsp.java:118)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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. <init> (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(DriverManager.java:525)
java.sql.DriverManager.getConnection(DriverManager.java:171)
org.apache.jsp.index_jsp._jspService(index_jsp.java:60)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Connection refused: connect
com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSConnection. <init> (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(DriverManager.java:525)
java.sql.DriverManager.getConnection(DriverManager.java:171)
org.apache.jsp.index_jsp._jspService(index_jsp.java:60)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.
哪位高手帮我看一下是什么原因啊?
[解决办法]
出现问题的可能原因:是否SQLSERVER版本与驱动程序包不符合?是否打了补丁?利用控制台能否进去?
[解决办法]
2000 打sp4补丁