首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败解决办法

2013-10-21 
com.microsoft.sqlserver.jdbc.SQLServerException: 到主机的 TCP/IP 连接失败HTTP Status 500 - --------

com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败
HTTP Status 500 - 

--------------------------------------------

type Exception report

message 

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

exception 

org.apache.jasper.JasperException: An exception occurred processing JSP page /judge.jsp at line 24

21: 
22: 
23: 
24: Connection conn= DriverManager.getConnection(url,user,password);  
25: 
26: 
27: Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);  


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:519)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

javax.servlet.ServletException: com.microsoft.sqlserver.jdbc.SQLServerException: 到主机  的 TCP/IP 连接失败。 java.net.ConnectException: Connection refused: connect
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
org.apache.jsp.judge_jsp._jspService(judge_jsp.java:124)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

com.microsoft.sqlserver.jdbc.SQLServerException: 到主机  的 TCP/IP 连接失败。 java.net.ConnectException: Connection refused: connect
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
java.sql.DriverManager.getConnection(DriverManager.java:582)
java.sql.DriverManager.getConnection(DriverManager.java:185)
org.apache.jsp.judge_jsp._jspService(judge_jsp.java:77)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.32 logs.


--------------------------------------------

Apache Tomcat/6.0.32


我的代码 如下:

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  


String url="jdbc:sqlserver://localhost:1433;DatabaseName=shuxue"; 
String user="sa"; 
String password=""; 




Connection conn= DriverManager.getConnection(url,user,password);  


Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);  

String sql="select * from student";

 
ResultSet rs=stmt.executeQuery(sql);  


while(rs.next()) {%>  

您的第一个字段内容为:<%=rs.getString(1)%>  
您的第二个字段内容为:<%=rs.getString(2)%>  
<%}%>  
<%out.print("数据库操作成功,恭喜你");%>  




<%rs.close();  
stmt.close();  
conn.close();  
%>  


[解决办法]
数据库没启动吧
在cmd里打 netstat -an 
[解决办法]
 findstr 1433
看有没有1433端口在监听,没有就是没启动。

热点排行