日期:2014-05-18  浏览次数:20687 次

请教jdbc数据库连接问题?
执行以下程序代码:
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   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: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   Sourc