<%Connection con  ;
  Statement st ;
 
  String sql = "select *   FROM [test].[dbo].[student]";
  String url = "jdbc:sqlserver://localhost;database=test";
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  con = DriverManager.getConnection(url,"sa","123456");
  st = con.createStatement();
  ResultSet rs = st.executeQuery(sql);
 
  out.print(rs.getString("name"));
  
  rs.close();
  st.close();
  
%>
一直连不上去,刚开始一直说
 [color=#993300]Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");[/color]
这句报错,改了改就成下面的错误了。
下载了一个sqljdbc4.jar到lib里面。
message javax.servlet.ServletException: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: Connection refused: connect. Please verify the connection properties and check that a SQL Server instance is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.description The server encountered an internal error that prevented it from fulfilling this request.

解决方案 »

  1.   

    楼主,你这个是访问数据库1433端口失败,而不是用户名密码不正确,因为如果验证不能用混合验证或者用户名密码错误,前提都是要连通1433端口你的错误很明显是1433不能连通,请检查防火墙,telnet IP 1433试试
      

  2.   

    你的TCP/IP协议没有打开。你打开Sqlserver配置工具,点击Sqlserver网络配置,展开MSSqlserver的协议,可以看见TCP/IP协议,右键“启用”即可。还不行的话可以追问。