我正在开发一个项目,它使用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