[java] Cannot create PoolableConnectionFactory

What is the problem? Can't connect to database?

   org.apache.commons.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.)

This question is related to java mysql hibernate

The answer is


In my case the solution was to remove the attribute

validationQuery="select 1"

from the (Derby DB) resource tag.


This happens because firewall blocks the database connection.

Disable the firewall and then try running the program again. It worked for me... :D


The problem could be due to too many users accessing the db at the same time. Either increase number of users that can concurrently access the db or kick out existing users (or apps). Use "Show processlist;" in the host DB to check connected users;

I came across another reason, catalina.policy file, could prohibit accessing specific IP/PORT


This is a network problem. Check out your database connectivity. Either your database connection link, username and password is wrong or your database server is stopped.


I changed the driver version in pom.xml and helped me

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.2.2</version>
</dependency>

I had a similar error. Changing the JDBC URL to use 127.0.0.1 instead of localhost helped.

Also had tried changing entries in catalina.policy file but that did not help. The entry I changed was for - java.net.SocketPermission


Go to my.ini file at the below path in windows C:\ProgramData\MySQL\MySQL Server 8.0\my.ini

and comment the below line

#bind-address=127.0.0.1

Then restart the MySQL server and connect.

Then you would be able to connect to MySQL from other IP address/machine.


I had the same problem with localhost in the source URL. I resolved with 127.0.0.1 instead of localhost.


I encounter same problem when I setup tomcat and mysql server on VirtualBox VM using chef.

in this case, I think true problem is VirtualBox seems to assign non-localhost address to eth0 like

[vagrant@localhost webapps]$ /sbin/ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:60:FC:47
      inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0

then auto-detection feature of chef's recipe using 10.0.2.15 as mysql server bind address.

so specify bind address for node params of chef's recipe solve problem in my case. I hope this information helps people using chef with vagrant.

{
  "name" : "db",
  "default_attributes" : {
   "mysql" : {
    "bind_address" : "localhost"
    ...
   }

try

jdbc:sqlserver://hostname:port;databaseName=TEST

It worked for me after adding colon before port number instead of a comma


This is the actual cause of the problem:

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

You have a database communication link problem. Make sure that your application have network access to your database (and the firewall isn't blocking ports to your database).


If you use apache tomcat 8.0 version, instead of it, use tomcat 7.0 I had tried localhost to 127.0.0.1 and power off firewall but not working, but use tomcat 7.0 and now working


This specific issue may arise in localhost also. We cannot rule out this is because network issue or internet connectivity issue. This issue will come even though all the database connection properties are correct.

I have faced the same issue when i have used host name. Instead use ip address. It will get resolved.


Here it was caused by avast antivirus. You can disable the avast firewall and let only windows firewall active.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to mysql

Implement specialization in ER diagram How to post query parameters with Axios? PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver' phpMyAdmin - Error > Incorrect format parameter? Authentication plugin 'caching_sha2_password' is not supported How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Connection Java-MySql : Public Key Retrieval is not allowed How to grant all privileges to root user in MySQL 8.0 MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

Examples related to hibernate

Hibernate Error executing DDL via JDBC Statement How does spring.jpa.hibernate.ddl-auto property exactly work in Spring? Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed JPA Hibernate Persistence exception [PersistenceUnit: default] Unable to build Hibernate SessionFactory Disable all Database related auto configuration in Spring Boot Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] HikariCP - connection is not available Hibernate-sequence doesn't exist How to find distinct rows with field in list using JPA and Spring? Spring Data JPA and Exists query