执行以下程序代码:
mybag.inc文件代码如下:
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="com.microsoft.jdbc.sqlserver.SQLServerDriver"%>
<%@ page import="java.lang.*"%>
<%@ page contentType="text/html; charset=gb2312"%>
<%
   request.setCharacterEncoding("gb2312");
   String CLASSFORNAME="com.microsoft.jdbc.sqlserver.SQLServerDriver";
   String SERVANDDB="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=school";
   String USER="sa";
   String PWD="sa";   
%>chaxun.jsp文件代码如下:<%@ include file="mybag.inc"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
//获得请求的参数。
String id=request.getParameter("tuser");
String psw=request.getParameter("pwd");
//连接数据库
Class.forName(CLASSFORNAME);
Connection con = DriverManager.getConnection(SERVANDDB,USER,PWD);
Statement statement=con.createStatement();
String isCorrect="select * from users where userid='" + id + "' and password='" + psw + "'";
ResultSet result=statement.executeQuery(isCorrect);
out.print(result.getString("username"));
%>
</body>
</html>运行chaxun.jsp文件后出现以下错误,小弟没有办法解决,请教各位大哥
type Exception reportmessage 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:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.tep3_jsp._jspService(tep3_jsp.java:94)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
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(DriverManager.java:525)
java.sql.DriverManager.getConnection(DriverManager.java:171)
org.apache.jsp.tep3_jsp._jspService(tep3_jsp.java:80)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.说明:jdbc三个驱动文件已复制到F:\Tomcat 5.0\common\lib下

解决方案 »

  1.   

    SQLServer2000下载补丁SP3或SP4打上就可以了
      

  2.   

    http://wstatic.xunlei.com/web/download.htm?cid=E56854A62158F7C179AB2799300A5EB501A8A506这下sp4
      

  3.   

    修改:
    out.print(result.getString("username"));

    if(result.next()){
    out.print(result.getString("username"));
    }else{
    out.print("-------no data");
    }
      

  4.   

    String isCorrect="select * from users where userid='" + id + "' and password='" + psw + "'";
    改为
    String isCorrect="select * from users where userid=" + id + " and password='" + psw + "'";
    还有就是
    out.print(result.getString("username"));
    改为
    if(result.next())
    {
    out.print(result.getString("username"));
    }
    else
    {
    out.print("没有此用户和密码");
    }