Cannot create PoolableConnectionFactory (Communications link failure)--Connection refused: connect

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

Caused by: java.lang.RuntimeException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

The 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.<clinit>(TimeSetUtils.java:22)
	... 3 more
Caused by: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

The 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 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The 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.<init>(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.<init>(ConnectionImpl.java:794)
	at com.mysql.jdbc.JDBC4Connection.<init>(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 more
Caused 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.<init>(Unknown Source)
	at java.net.Socket.<init>(Unknown Source)
	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:254)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:295)
	... 23 more
2012-2-19 15:35:27 edu.gzucm.yjsglxt.base.util.InitInfoUtil <clinit>
严重: null
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

The 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.<clinit>(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.<init>(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 failure

The 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.<init>(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.<init>(ConnectionImpl.java:794)
	at com.mysql.jdbc.JDBC4Connection.<init>(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 more
Caused 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.<init>(Unknown Source)
	at java.net.Socket.<init>(Unknown Source)
	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:254)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:295)
	... 33 more
2012-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 <?xml version="1.0" encoding="UTF-8"?>
 2 <!--
 3   Licensed to the Apache Software Foundation (ASF) under one or more
 4   contributor license agreements.  See the NOTICE file distributed with
 5   this work for additional information regarding copyright ownership.
 6   The ASF licenses this file to You under the Apache License, Version 2.0
 7   (the "License"); you may not use this file except in compliance with
 8   the License.  You may obtain a copy of the License at
 9 
10       http://www.apache.org/licenses/LICENSE-2.0
11 
12   Unless required by applicable law or agreed to in writing, software
13   distributed under the License is distributed on an "AS IS" BASIS,
14   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   See the License for the specific language governing permissions and
16   limitations under the License.
17 --><!-- The contents of this file will be loaded for each web application --><Context>
18 
19     <!-- Default set of monitored resources -->
20     <WatchedResource>WEB-INF/web.xml</WatchedResource>
21 
22     <!-- Uncomment this to disable session persistence across Tomcat restarts -->
23     <!--
24     <Manager pathname="" />
25 -->
26 
27     <!-- Uncomment this to enable Comet connection tacking (provides events
28          on session expiration as well as webapp lifecycle) -->
29     <!--
30     <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
31 -->
32      <Resource auth="Container" 
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 </Context>

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

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

应该改成:

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

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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏后端云

resize失败原因调查

对一个vm做resize,即从一个小的flavor换一个大的flavor,没有成功

1433
来自专栏Java3y

从零开始写项目第一篇【搭建环境】

使用Maven搭建SSM环境 SSM需要的基础jar包有哪些??整理一下: c3p0数据连接池 springMVC的JSON springAOP springC...

53510
来自专栏为数不多的Android技巧

Android 插件化原理解析——Hook机制之AMS&PMS

在前面的文章中我们介绍了DroidPlugin的Hook机制,也就是代理方式和Binder Hook;插件框架通过AOP实现了插件使用和开发的透明性。在讲述Dr...

1311
来自专栏JAVA后端开发

JAVA实现编写平台代码生成器

[项目中经常写CRUD,但实际这些工作,我觉得如果有一个完整的代码规范,完全可以自动生成,加快开发效率. 代码生成器技术原理不复杂,一般就是写好一个模板生成一...

9152
来自专栏Golang语言社区

Go 单元测试与接口

Good code and unit testing come hand in hand, and sometimes the bridge between t...

2923
来自专栏xingoo, 一个梦想做发明家的程序员

Oozie调度报错——ORA-00918:未明确定义列

Oozie在执行sqoop的时候报错,同样的SQL在sqoop中可用,在oozie中不可用: Caused by: java.sql.SQLSyntaxErro...

23810
来自专栏JackieZheng

学习SpringMVC——你们要的REST风格的CRUD来了

  来来来,让一下,客官,您要的REST清蒸CRUD来了,火候刚刚好,不油不腻,请慢用~~~   如果说前面是准备调料,洗菜,切菜,摆盘,那么今天就来完整的上道...

34410
来自专栏一个会写诗的程序员的博客

13.12 Spring Boot集成Security中遇到的问题13.12 Spring Boot集成Security中遇到的问题问题1:Spring Boot集成Security使用数据库用户角色

sql语法手误。1?这地方写错了,应该是?1。这在敲代码的时候,手速一旦稍有不慎,就会导致前后顺序颠倒,而导致输入错误。这个虽然说是“低级错误”,但是错误搞起来...

982
来自专栏蘑菇先生的技术笔记

多线程中的锁系统(四)-谈谈自旋锁

2987
来自专栏颇忒脱的技术博客

Servlet 3.1 Async IO分析

Servlet Async Processing提供了一种异步请求处理的手段(见我的另一篇文章Servlet 3.0 异步处理详解),能够让你将Http thr...

1503

扫码关注云+社区

领取腾讯云代金券