Communication link Failure : access java web app [duplicate] - java

This question already has answers here:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
(51 answers)
Closed 3 years ago.
I was trying to access my java web app , which i have containerised with docker containers and i also have containerised my mysql database in a different container , both container are running on the default docker network , and i also tried to ping those containers from each other and i got positive results from it , but when i try to access it on my localhost (as i have mapped the ports of the tomcat server to the host ) machine it shows
Error
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.
I have read a little bit about this error , its related to some sort of connectivity issue with database but through pingcommand , i checked the connection.
What could be the reason of this error?

1) If it is bound to 127.0.0.1 and you can't connect using "localhost", make sure it's not resolving to the IPv6 localhost address instead of IPv4. (or just use the IP address)
2) Check the port that MySQL is listening on (Default 3306).
3) Make sure you're using the right JDBC connector for your JDK.
Check this below code in your application.yml or application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/<<DB_NAME>>
spring.datasource.username=root (In my case)

Related

connecting to remote mysql server using intelij [duplicate]

This question already has answers here:
Solving a "communications link failure" with JDBC and MySQL [duplicate]
(25 answers)
Closed 4 years ago.
I have mysql database running on server that i access using <ip>/phpmyadmin.
I want to create data source in intelij and i am trying to connect there.
Host: <ip>/phpmyadmin
Database: <database_name>
User:root
password: *****
Url: jdbc:mysql://<ip>/phpmyadmin:3306/<database_name>
However using this i recieve error from intelij:
> Connection to jdbc:mysql://<ip>/phpmyadmin:3306/<database_name>
> failed. [08S01] 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.
Why is this happening? Going to <ip>/phpmyadmin in broswer nicely delegates me to phpmyadmin, so why is intelij complaining? The url should be correct, the mysql database is running on port 3306 on server.
How can i fix this?
thanks for help!
Remove phpadmin path from your host and try to connect again. If it doesn't work, check on which port MySQL is running by
mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';

cant connect my driver to from eclipse to sql server [duplicate]

This question already has answers here:
JDBC connection failed, error: TCP/IP connection to host failed
(9 answers)
Closed 5 years ago.
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:191)
at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:242)
at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2369)
at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:551)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1963)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1628)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1459)
I'm facing this exception after I tried to connect with my driver through the new database profile.
The information I have was correct and the TCP port was enabled and the firewall was turned off.
I'm using Microsoft SQL server 2008 JDBC driver and I've added the jars.
A "connection refused" is rarely caused by the connecting client, i.e. the JDBC client within your Eclipse setup. A good check is to open a shell (e.g. cmd.exe on Windows) and do a
telnet [server name used in JDBC configuration] 1433
On newer Windows installations you need to install the telnet client because it's not part of the standard installation anymore (Settings -> Software -> Add/Remove Features).
If that leads to a similar error message you can focus your trouble shooting to the network part of your system, since the JDBC side is completely uninvolved. If you can connect, make sure that the server name resolves to the same IP when using the command prompt as it's resolved within Java (I once had this effect which took quite a time to find that out). Especially with localhost as server name one might resolve to 127.0.0.1 while the other resolvs to ::1.

Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure [duplicate]

This question already has answers here:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
(51 answers)
Closed 6 years ago.
I Have developed an application to capture data, retrieve information,delete and also update info. The application is developed in java swing and hibernate and uses MySQL version 5.5 as a database. I tested it on my local server or local host and its working fine. So now i took it a step further trying to access the database on the remote server. Please note that also the MySQL version i use on my local server is the same as the MySQL in the remote server.
I get the following error:
Internal Exception: 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.
Error Code: 0
The problem is that your MySqlConnector/Driver can't establish a Connection to the remote server.
Check your jdbc URL and also the check if the wrong ports are used.
Maybe the Mysql DB is not reachable from outside, than you can use a port forwarding with ssh, for example :
port forwarding:
ssh -L3306:127.0.0.1:3306 user#remoteServer
than change your jdbc url to:
jdbc:mysql://localhost:3306/database
Explanation:
-L port:host:hostport
Specifies that the given port on the local (client) host is to be
forwarded to the given host and port on the remote side.
...
Whenever a
connection is made to this port, the connection is forwarded over
the secure channel, and a connection is made to host port
hostport from the remote machine.
Source: http://www.openbsd.org/cgi-bin/man.cgi?query=ssh&sektion=1
That means you request with your MySQL JDBC Driver(jdbc url) on the local 3306 port
will be forwarded to the remote server on his local 3306 port,
where the Mysql Database is listing.

IOException: Network adapter could not establish the connection [duplicate]

This question already has answers here:
The Network Adapter could not establish the connection when connecting with Oracle DB
(4 answers)
Closed 6 years ago.
We started to have this "Network adapter could not establish the connection" problem in our production environment from time to time, I did a lot of google and went through some questions here but still didn't get the solution.
Here are some information about our environment:
We are using RAC with 2 oracle instances (version 10.2.0.4).
We have several app servers (JBoss AS5) running on top of the RAC.
The connection url in oracle-ds.xml is "jdbc:oracle:thin:#(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = db1_vip)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST=db2_vip)(PORT = 1521))(LOAD_BALANCE = yes))(CONNECT_DATA=(SERVER = DEDICATED)(SERVICE_NAME = G1db)(FAILOVER_MODE =(TYPE =SELECT)(METHOD = BASIC)(RETRIES = 120)(DELAY = 5))))"
We added db1_vip/db2_vip as well the actual ip of 2 oracle instances to the /etc/hosts of both app servers
There IS firewall between oracle instances and app servers, but we opened the 1521 port on both oracle instances.
We've run following tests to check if there is any problem on network or oracle TNS listener:
run ping from app servers to both oracle instances, everything works fine without any packet loss.
telnet the 1521 port from app servers to both oracle instances, nothing wrong.
tnsping also works fine.
We checked listener log but found nothing valuable.
The most weird thing is that this error happens around 10 times an hour on one app server, but only happens 1 or 2 times a day on another app server.
Can anyone shed some light on this error?
Thanks
[EDIT4]: We found timeout problem when tnsping one oracle instance, so we changed the jdbc url to connect only one instance and found the IOException never happened again, so we think the problem is related with database and the DBA team will continue look into this.
[EDIT3]: We did following tries:
disabled the firewall between app servers and database servers
Use ip instead of host name
use wireshark to check if there is any tcp packet problem.
none of them succeed, someone please help~
[EDIT]: the error stack trace:
java.sql.SQLException: Io Exception: The Network Adapter could not establish the connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:207)
... 5 more
The error
java.sql.SQLException: Io Exception: The Network Adapter could not
establish the connection
has nothing to do with Java/JDBC.
This is the error you get when there's something wrong with your network setup. My guess, firewall problem. Can you disable it and see if the error is still there?
edit the connection and test it although your tnsping found!, if use virtualbox (in adapter check permit all), in my case, the error was when i use the ip, instead of use localhost

(Enterprise GlassFish v3 build 11) Communication link problem (MySQL DB)

I get a communication link failure while application tries to establish a connection with DB.
[#|2010-04-08T20:09:57.825+0300|SEVERE|glassfish3.0|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=24;_ThreadName=Thread-1;|Cannot connect to database server = 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.|#]
Precisely at this string:
Statement s = conn.createStatement();
where conn is defined as follows:
private static java.sql.Connection conn;
For this app I have set a connection pool with default parameters and currently it (app) uses both JPA and direct JDBC queries. Recreation of connection pool gave nothing, connection pool ping gave next message:
Ping Connection Pool for pool is Failed. Ping failed Exce
ption - Connection could not be allocated because: Communications lin
k failure%%%EOL%%%%%%EOL%%%The last packet sent successfully to the s
erver was 0 milliseconds ago. The driver has not received any packets
from the server. Please check the server.log for more details.%%%EOL
%%%Ping failed Exception - Connection could not be allocated because:
Communications link failure
and flushing the connection pool gave:
com.sun.enterprise.admin.cli.CommandException: remote failure: Failed to flush connection pool ...
However I can connect to the database from a terminal. Besides I have the same app working on my local machine with identical connection pool settings.
Any one has an idea on whats going on or how to solve the trouble?
Such problem could be if you have mysql server & glassfish server on the same host, and in mysql configuration you have option bind to some public address (for example 192.168.0.1 of eth0 interface) that normally successfully working with simple jdbc/jpa using user#localhost, but they don`t in a case of glassfish JTA, instead to bind to some of local address you getting link failure. As rule you could not bind to any local (localhost/127.0.0.1) addresses of such mysql host if public address presented.
Example:
my.cnf
bind-address = 127.0.0.1
bind-address = 192.168.0.1
127.0.0.1 - assign to lo interface
192.168.0.1 - assign to eth0 interface
It is glassfish-mysql bug.
Currently in order to use JTA, you should not bind mysql to such address. (remove "bind-address=192.168.0.1" from my.cnf). Or use user#192.168.0.1 what is less secure.
Besides I have the same app working on my local machine with identical connection pool settings.
Are you connecting to the same database? If yes, maybe check that you're using the same JDBC driver.
In my case I set :
URL : jdbc:mysql://10.81.35.66:3306/testDB
and
url : jdbc:mysql://10.81.31.76:3306/vectordb
both When setting values while creating connection pool in additional property part
on glass fish admin console .

Categories