Cannot create PoolableConnectionFactory
Asked Answered
N

16

29

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.)
Nucleus answered 5/3, 2011 at 12:4 Comment(2)
Please post the full stacktrace instead. We can't understand what is the root cause of this error without the stacktrace.Madness
In Linux, I had to start the service by typing "service mysqld start"Fib
M
30

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).

Madness answered 5/3, 2011 at 12:17 Comment(1)
For posterity, I run into this problem every month or so when I restart a machine in the dev environment and my database isn't running. I hope this helps someone else when they make the same silly mistake.Dipeptide
L
7

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

Logistician answered 4/1, 2013 at 10:50 Comment(0)
A
4

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.

Ammadis answered 11/7, 2012 at 4:14 Comment(0)
E
3

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

Essive answered 8/12, 2014 at 12:49 Comment(0)
M
2

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"
    ...
   }
Mesitylene answered 14/9, 2013 at 8:25 Comment(0)
K
2

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.

Kosey answered 21/1, 2019 at 14:7 Comment(0)
R
1

This happens because firewall blocks the database connection.

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

Retrospective answered 25/3, 2012 at 10:46 Comment(1)
Or I just changed port from 3307 to 3306.Israel
S
1

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>
Shaffert answered 2/10, 2018 at 8:22 Comment(0)
B
1

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.

Barcellona answered 13/12, 2018 at 10:49 Comment(0)
B
0

In my case the solution was to remove the attribute

validationQuery="select 1"

from the (Derby DB) resource tag.

Bamford answered 12/10, 2018 at 3:25 Comment(0)
E
0

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

Engram answered 29/4, 2019 at 2:51 Comment(1)
There are a bunch of reasons not to connect.Carrick
K
0

try

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

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

Kyne answered 26/6, 2020 at 17:55 Comment(0)
R
0

In case if you are using database in cloud & you get this issue: In my case GCP SQL instance - Mysql.

Go to instance, add a name & network to allow. As in the screenshot below. It should work then.

Snap from GCP SQL

Rosin answered 24/8, 2022 at 11:4 Comment(2)
This is my case, but what if the connection is trying to be made from a cloud shell or a dataflow job, how can you add a network if everytime you run this shell or job it will have a different network?Pensioner
You are allowing the IP to communicate to this instance. One way: The machine from where it is getting connected should have private IP reserved, else you need to perform this every time (or) Other way: create a private IP to the database instance and use that in the dataflow template/ shell where you are running to connect.Rosin
V
0

Very hard to believe, but in my case I had to put two spaces before "(DESCRIPTION", on tnsnames.ora:

SOMEDATABASE =
  (DESCRIPTION = 
    (ADDRESS = (PROTOCOL = TCP)(HOST = xxx)(PORT = xxx))
    (CONNECT_DATA =
        (SERVICE_NAME = xxx)
    )
  )
Vertumnus answered 30/4 at 17:45 Comment(2)
The question is tagged "mysql". It is not tagged "oracle", so how does file tnsnames.ora help?Bergstrom
Ok, looks like I have to pay more attention to the tags. Thanks for clarifying.Vertumnus
T
-1

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

Trudi answered 14/4, 2015 at 5:24 Comment(0)
B
-1

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

Betthel answered 19/4, 2015 at 12:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.