Home Database Mysql Tutorial Cannot create PoolableConnectionFactory (Communications link_MySQL

Cannot create PoolableConnectionFactory (Communications link_MySQL

May 27, 2016 pm 02:29 PM

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.<clinit>(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.<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 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.<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 more2012-2-19 15:35:27 edu.gzucm.yjsglxt.base.util.InitInfoUtil <clinit>严重: 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.<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 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.<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 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.<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 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
Copy after login

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

配置如下:

 1 <?xml version="1.0" encoding="UTF-8"?><br /> 2 <!--<br /> 3   Licensed to the Apache Software Foundation (ASF) under one or more<br /> 4   contributor license agreements.  See the NOTICE file distributed with<br /> 5   this work for additional information regarding copyright ownership.<br /> 6   The ASF licenses this file to You under the Apache License, Version 2.0<br /> 7   (the "License"); you may not use this file except in compliance with<br /> 8   the License.  You may obtain a copy of the License at<br /> 9 <br />10       http://www.apache.org/licenses/LICENSE-2.0<br />11 <br />12   Unless required by applicable law or agreed to in writing, software<br />13   distributed under the License is distributed on an "AS IS" BASIS,<br />14   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br />15   See the License for the specific language governing permissions and<br />16   limitations under the License.<br />17 --><!-- The contents of this file will be loaded for each web application --><Context><br />18 <br />19     <!-- Default set of monitored resources --><br />20     <WatchedResource>WEB-INF/web.xml</WatchedResource><br />21 <br />22     <!-- Uncomment this to disable session persistence across Tomcat restarts --><br />23     <!--<br />24     <Manager pathname="" /><br />25 --><br />26 <br />27     <!-- Uncomment this to enable Comet connection tacking (provides events<br />28          on session expiration as well as webapp lifecycle) --><br />29     <!--<br />30     <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /><br />31 --><br />32      <Resource auth="Container" <br />33      driverClassName="com.mysql.jdbc.Driver" <br />34      maxActive="100" <br />35      maxIdle="30" <br />36      maxWait="10000" <br />37      name="jdbc/mysql" <br />38      password="root" <br />39      type="javax.sql.DataSource" <br />40      url="jdbc:mysql:///yjsglxt?characterEncoding=UTF-8" <br />41      username="root"/><br />42 </Context>
Copy after login

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

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

应该改成:

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

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

 

bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Explain InnoDB Full-Text Search capabilities. Explain InnoDB Full-Text Search capabilities. Apr 02, 2025 pm 06:09 PM

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

Difference between clustered index and non-clustered index (secondary index) in InnoDB. Difference between clustered index and non-clustered index (secondary index) in InnoDB. Apr 02, 2025 pm 06:25 PM

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values ​​and pointers to data rows, and is suitable for non-primary key column queries.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

The relationship between mysql user and database The relationship between mysql user and database Apr 08, 2025 pm 07:15 PM

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

Can mysql and mariadb coexist Can mysql and mariadb coexist Apr 08, 2025 pm 02:27 PM

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

RDS MySQL integration with Redshift zero ETL RDS MySQL integration with Redshift zero ETL Apr 08, 2025 pm 07:06 PM

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

See all articles