检验数据库是否连接成功的原程序如下:<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>数据库操作</title>
</head><body>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=xionglu"; String user="sa"; String password="sql"; Connection conn= DriverManager.getConnection(url,user,password); Statement stmt=conn.createStatement(); String sql="insert into dd values('4','xxx','44')"; stmt.executeUpdate(sql); 
%> 
</body>
</html>
出现的错误页面如下:type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Exception in JSP: /ok.jsp:2017: 
18: String password="sql"; 
19: 
20: Connection conn= DriverManager.getConnection(url,user,password); 
21: 
22: Statement stmt=conn.createStatement(); 
23: 
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.ok_jsp._jspService(ok_jsp.java:81)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
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(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.ok_jsp._jspService(ok_jsp.java:62)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
望高手门指点指点,谢谢大家~!

解决方案 »

  1.   

    你有没有把下面三个包导入工程?
    检查数据库
    msbase.jar
    mssqlserver.jar
    msutil.jar
      

  2.   

    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); 
    没有newInstance()详细看一下:
    http://tech.163.com/05/0830/15/1SDQL2CI00091589.html
      

  3.   

    Class.forName是静态方法
    .newInstance()应该是不用的
      

  4.   

    javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.从这里看好像是在创建连接的时候出了问题
      

  5.   

    3个包都放进去了,环境变量也设了,这个程序在别人机器上运行都能连接上,而且和我用的是一样的sql server 2000+SQLServer 2000 Driver for JDBCjavax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.从这句我也感觉是驱动器的问题,但是我重新下载过别的驱动器也还是不行楼上的兄弟说的补丁是什么?是sql server 2000的补丁吗,我看别人也没打过补丁啊