一段JSP代码
<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String connStr="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jdbc";
Connection conn=DriverManager.getConnection(connStr," "," ");
Statement sql=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String sqlStr="select * from account";
ResultSet rs=sql.executeQuery(sqlStr);
%>
网页报错:org.apache.jasper.JasperException: javax.servlet.ServletException: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:532)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:408)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause javax.servlet.ServletException: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:855)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)
org.apache.jsp.selectAccountMove_jsp._jspService(selectAccountMove_jsp.java:127)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
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:582)

解决方案 »

  1.   

    jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jdbc";<----jdbc:sqlserver://localhost:1433;DatabaseName=jdbc";<----modified
      

  2.   

    确认你的SQL 打上了SP4补丁?同时Class.forName(); 加载驱动正确
      

  3.   

    楼主这个问题我也最近遇到这个问题,呵呵 ,而且楼主这个将数据库运算的写在jsp很不好的 。影响效率和以后的修改,网上你可能也查了资料,有些说是SP3或者SP4补丁包的原因,其实不然。应该你的写法都没问题 。出的问题的不是这个地方。可能是你其他的地方出问题了 。如要深一步的探讨的。发邮箱:[email protected].
      

  4.   

    你的用户名和密码都是空?或者你的数据库名字不能这样命名。
    <%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); 
    String url="jdbc:microsoft:sqlserver://192.1681.4:1433;DatabaseName=jdbc"; 
    //pubs为你的数据库的 
    String user="sa"; 
    String password="SQLServer@OA"; 
    Connection conn= DriverManager.getConnection(url,user,password); 
    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); 
    String sqlStr="select * from account";
    ResultSet rs=sql.executeQuery(sqlStr);
    while(rs.next()){
    这里是结果 。
    rs.getString(1);
    }
    rs.close(); 
    %>