欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Cannot create PoolableConnectionFactory (Communications link_MySQL

程序员文章站 2022-05-06 12:17:06
...
bitsCN.com

今天在做web项目的时候碰到了这样的一个异常:

Caused by: java.lang.RuntimeException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failureThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)	at edu.gzucm.yjsglxt.base.util.TimeSetUtils.getTimeSets(TimeSetUtils.java:52)	at edu.gzucm.yjsglxt.base.util.TimeSetUtils.(TimeSetUtils.java:22)	... 3 moreCaused by: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failureThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)	at edu.gzucm.yjsglxt.base.util.TimeSetUtils.getTimeSets(TimeSetUtils.java:32)	... 4 moreCaused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failureThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)	at java.lang.reflect.Constructor.newInstance(Unknown Source)	at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)	at com.mysql.jdbc.MysqlIO.(MysqlIO.java:346)	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2334)	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2371)	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)	at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:794)	at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)	at java.lang.reflect.Constructor.newInstance(Unknown Source)	at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)	at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)	at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)	... 7 moreCaused by: java.net.ConnectException: Connection refused: connect	at java.net.PlainSocketImpl.socketConnect(Native Method)	at java.net.PlainSocketImpl.doConnect(Unknown Source)	at java.net.PlainSocketImpl.connectToAddress(Unknown Source)	at java.net.PlainSocketImpl.connect(Unknown Source)	at java.net.SocksSocketImpl.connect(Unknown Source)	at java.net.Socket.connect(Unknown Source)	at java.net.Socket.connect(Unknown Source)	at java.net.Socket.(Unknown Source)	at java.net.Socket.(Unknown Source)	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:254)	at com.mysql.jdbc.MysqlIO.(MysqlIO.java:295)	... 23 more2012-2-19 15:35:27 edu.gzucm.yjsglxt.base.util.InitInfoUtil 严重: nullorg.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failureThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)	at edu.gzucm.yjsglxt.base.util.DataSourceUtil.getConnection(DataSourceUtil.java:67)	at edu.gzucm.yjsglxt.base.util.InitInfoUtil.(InitInfoUtil.java:265)	at edu.gzucm.yjsglxt.base.filter.PrepareFilter.init(PrepareFilter.java:116)	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:273)	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:254)	at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:372)	at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:98)	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4584)	at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5262)	at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5257)	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)	at java.util.concurrent.FutureTask.run(Unknown Source)	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)	at java.lang.Thread.run(Unknown Source)Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failureThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)	at java.lang.reflect.Constructor.newInstance(Unknown Source)	at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)	at com.mysql.jdbc.MysqlIO.(MysqlIO.java:346)	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2334)	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2371)	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)	at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:794)	at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)	at java.lang.reflect.Constructor.newInstance(Unknown Source)	at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)	at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)	at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)	at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)	... 17 moreCaused by: java.net.ConnectException: Connection refused: connect	at java.net.PlainSocketImpl.socketConnect(Native Method)	at java.net.PlainSocketImpl.doConnect(Unknown Source)	at java.net.PlainSocketImpl.connectToAddress(Unknown Source)	at java.net.PlainSocketImpl.connect(Unknown Source)	at java.net.SocksSocketImpl.connect(Unknown Source)	at java.net.Socket.connect(Unknown Source)	at java.net.Socket.connect(Unknown Source)	at java.net.Socket.(Unknown Source)	at java.net.Socket.(Unknown Source)	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:254)	at com.mysql.jdbc.MysqlIO.(MysqlIO.java:295)	... 33 more2012-2-19 15:35:27 org.apache.coyote.AbstractProtocol start信息: Starting ProtocolHandler ["http-bio-8080"]2012-2-19 15:35:27 org.apache.coyote.AbstractProtocol start信息: Starting ProtocolHandler ["ajp-bio-8009"]2012-2-19 15:35:27 org.apache.catalina.startup.Catalina start信息: Server startup in 2983 ms

我知道是连接数据库的时候出现了错误,我检查了我的tomcat的配置文件context.xml文件

配置如下:

 1 
2
18
19
20 WEB-INF/web.xml
21
22
23
26
27
29
32 33 driverClassName="com.mysql.jdbc.Driver"
34 maxActive="100"
35 maxIdle="30"
36 maxWait="10000"
37 name="jdbc/mysql"
38 password="root"
39 type="javax.sql.DataSource"
40 url="jdbc:mysql:///yjsglxt?characterEncoding=UTF-8"
41 username="root"/>
42

查了一下,才发现原来是url这里有问题:

1 url="jdbc:mysql:///yjsglxt?characterEncoding=UTF-8" 

应该改成:

1 url="jdbc:mysql://localhost:3306/yjsglxt?characterEncoding=UTF-8" 

这样做了以后,再次运行一下项目,嘿嘿,可以了……………………

bitsCN.com
相关标签: 今天