问题描述
org.apache.tomcat.dbcp.dbcp.SQLNestedException:CannotcreatePoolableConnectionFactory(到主机的TCP/IP连接失败。java.net.ConnectException:Connectionrefused:connect)atorg.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)atorg.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)atorg.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)atcom.wsy.Connsqlserver.getConnection(Connsqlserver.java:29)atcom.wsy.Connsqlserver.executeQuery(Connsqlserver.java:49)atcom.wsy.Selectsql.selectNews(Selectsql.java:138)atorg.apache.jsp.index_jsp._jspService(index_jsp.java:108)atorg.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:723)atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:723)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atcom.wsy.Filter.ModifyCode.doFilter(ModifyCode.java:23)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)atorg.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)atorg.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)atorg.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1774)atjava.lang.Thread.run(Thread.java:619)Causedby:com.microsoft.sqlserver.jdbc.SQLServerException:到主机的TCP/IP连接失败。java.net.ConnectException:Connectionrefused:connectatcom.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(UnknownSource)atcom.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(UnknownSource)atcom.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(UnknownSource)atcom.microsoft.sqlserver.jdbc.SQLServerConnection.connect(UnknownSource)atcom.microsoft.sqlserver.jdbc.SQLServerDriver.connect(UnknownSource)atorg.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)atorg.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)atorg.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)atorg.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)...27morejava.lang.NullPointerExceptionatcom.wsy.Connsqlserver.executeQuery(Connsqlserver.java:51)atcom.wsy.Selectsql.selectNews(Selectsql.java:138)atorg.apache.jsp.index_jsp._jspService(index_jsp.java:108)atorg.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:723)atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:723)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atcom.wsy.Filter.ModifyCode.doFilter(ModifyCode.java:23)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)atorg.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)atorg.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)atorg.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1774)atjava.lang.Thread.run(Thread.java:619)org.apache.jasper.JasperException:AnexceptionoccurredprocessingJSPpage/index.jspatline4239:<tr>40:<tdcolspan="2"rowspan="2"width="405"height="20"><tablewidth="100%"border="0"background="images/17.gif"height="20">41:<%42:Collectiontemp2=sql.selectNews();43:Iteratorit2=temp2.iterator();44:while(it2.hasNext()){45:Newsnews=(News)it2.next();Stacktrace:atorg.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:723)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atcom.wsy.Filter.ModifyCode.doFilter(ModifyCode.java:23)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)atorg.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)atorg.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)atorg.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1774)atjava.lang.Thread.run(Thread.java:619)Causedby:java.lang.NullPointerExceptionatcom.wsy.Connsqlserver.close(Connsqlserver.java:73)atcom.wsy.Selectsql.selectNews(Selectsql.java:154)atorg.apache.jsp.index_jsp._jspService(index_jsp.java:108)atorg.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:723)atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)...18more++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++怎么看Tcp/Ip的端口情况?使用ProxoolConnectionPool连接池。
解决方案
解决方案二:
Proxool.properties数据库sql2000jdbc-0.proxool.alias=netjdbc-0.proxool.driver-class=com.microsoft.jdbc.sqlserver.SQLServerDriverjdbc-0.proxool.driver-url=jdbc:microsoft:sqlserver://127.0.0.1:7788;DatabaseName=db_netjdbc-0.user=sajdbc-0.password=jdbc-0.proxool.maximum-connection-count=10jdbc-0.proxool.prototype-count=4jdbc-0.proxool.house-keeping-test-sql=selectCURRENT_DATEjdbc-0.proxool.verbose=truejdbc-0.proxool.statistics=10s,1m,1djdbc-0.proxool.statistics-log-level=DEBUG++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++context.xml<?xmlversion='1.0'encoding='utf-8'?><Context><Resourcename="jdbc/ConnectionPool"type="javax.sql.DataSource"auth="Container"driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"url="jdbc:microsoft:sqlserver://127.0.0.1:7788;DatabaseName=db_net"username="sa"password=""maxActive="4"maxIdle="2"maxWait="6000"/></Context><?xmlversion='1.0'encoding='utf-8'?><Context><Resourcename="jdbc/ConnectionPool"type="javax.sql.DataSource"auth="Container"driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"url="jdbc:microsoft:sqlserver://127.0.0.1:7788;DatabaseName=db_net"username="sa"password=""maxActive="4"maxIdle="2"maxWait="6000"/></Context>
解决方案三:
CannotcreatePoolableConnectionFactory(到主机的TCP/IP连接失败。java.net.ConnectException:Connectionrefused:connect)