0

这可能是一个愚蠢的问题,但已经带走了我的睡眠..

我正在开发一个项目,它使用 JSP 通过 jdbc 连接器连接到 SQL Server 2005。下面给出了代码的相关部分(我认为)。

String user=request.getParameter("t1");
String pass=request.getParameter("t2");

int flag=0;
String userName = "sa";
String password = "abcdefgh";
String url = "jdbc:sqlserver://localhost:1433;databaseName=OnlineExam";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection(url, userName, password);
    try {
// Load the JDBC driver

 String query1 = "SELECT UserName,Password FROM LOGIN";
 Statement stmt = con.createStatement();
 ResultSet rs = stmt.executeQuery(query1);
 while (rs.next()) {
 String username=rs.getString(1);
 String passwordd=rs.getString(2);
 if(user.equals(username) && pass.equals(passwordd))
 {  
   flag=1;
 }

 }

 }
   catch (Exception e) {
   System.out.println(e.toString());
 } 

但是每当我尝试运行这个项目时,它都会出错

type Exception report

message

description
The server encountered an internal error () that prevented it from fulfilling this      
request.

exception
 javax.servlet.ServletException: com.microsoft.sqlserver.jdbc.SQLServerException:The  
 TCP/IP connection to the host  has failed. java.net.ConnectException: Connection    
 refused: connect


root cause
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host  has   
failed. java.net.ConnectException: Connection refused: connect
4

0 回答 0