Cannot create PoolableConnectionFactory (Communications link_MySQL
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
我知道是连接数据库的时候出现了错误,我检查了我的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>
查了一下,才发现原来是url这里有问题:
1 url="jdbc:mysql:///yjsglxt?characterEncoding=UTF-8"
应该改成:
1 url="jdbc:mysql://localhost:3306/yjsglxt?characterEncoding=UTF-8"
这样做了以后,再次运行一下项目,嘿嘿,可以了……………………

Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

AI Hentai Generator
Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

Heiße Werkzeuge

Notepad++7.3.1
Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version
Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1
Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6
Visuelle Webentwicklungstools

SublimeText3 Mac-Version
Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Heiße Themen

In dem Artikel werden mithilfe der Änderungstabelle von MySQL Tabellen, einschließlich Hinzufügen/Löschen von Spalten, Umbenennung von Tabellen/Spalten und Ändern der Spaltendatentypen, erläutert.

In Artikel werden die Konfiguration der SSL/TLS -Verschlüsselung für MySQL, einschließlich der Erzeugung und Überprüfung von Zertifikaten, erläutert. Das Hauptproblem ist die Verwendung der Sicherheitsauswirkungen von selbstsignierten Zertifikaten. [Charakterzahl: 159]

In Artikel werden Strategien zum Umgang mit großen Datensätzen in MySQL erörtert, einschließlich Partitionierung, Sharding, Indexierung und Abfrageoptimierung.

In Artikel werden beliebte MySQL -GUI -Tools wie MySQL Workbench und PhpMyAdmin beschrieben, die ihre Funktionen und ihre Eignung für Anfänger und fortgeschrittene Benutzer vergleichen. [159 Charaktere]

In dem Artikel werden in MySQL die Ablagerung von Tabellen mithilfe der Drop -Tabellenerklärung erörtert, wobei Vorsichtsmaßnahmen und Risiken betont werden. Es wird hervorgehoben, dass die Aktion ohne Backups, die Detaillierung von Wiederherstellungsmethoden und potenzielle Produktionsumfeldgefahren irreversibel ist.

In Artikeln werden ausländische Schlüssel zur Darstellung von Beziehungen in Datenbanken erörtert, die sich auf Best Practices, Datenintegrität und gemeinsame Fallstricke konzentrieren.

Artikel erläutert die Sicherung von MySQL gegen SQL-Injektions- und Brute-Force-Angriffe unter Verwendung vorbereiteter Aussagen, Eingabevalidierung und starken Kennwortrichtlinien (159 Zeichen).

In dem Artikel werden in verschiedenen Datenbanken wie PostgreSQL, MySQL und MongoDB Indizes für JSON -Spalten in verschiedenen Datenbanken erstellt, um die Abfrageleistung zu verbessern. Es erläutert die Syntax und die Vorteile der Indizierung spezifischer JSON -Pfade und listet unterstützte Datenbanksysteme auf.
