Can we configure spring.datasource.url for external mysql server - java

For my Springboot project I can't connect to a mysql that I had hosted on a site. With a local mysql (workbench) it works well but when I replace the localhost url with that of the host it does not work and I have the following error message:
com.mysql.cj.jdbc.exceptions.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.
here is my code in application properties:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/word?
spring.datasource.username=root
spring.datasource.password=root
I replace the following line of code with my Database Host:
spring.datasource.url=jdbc:mysql://db.example.net:3306/word?
spring.datasource.url=jdbc:mysql://db.example.net:3306/word?

It could be many things
IPTables/firewalld based firewall on either machines
Firewall on the network
Or simply IP is not reachable
If all the above 3 is done right then it could be a config on MySQL server side to not accept remote connections. Flip that flag (and possibly restart the MySQL service)
I would start from pinging the DB IP. If that's accessible you can rule out the line number 3. Then next I would look for the aforementioned config on mysql server side.

I just received a message from the support, they don't allow connection from any IP address. Thanks for answers!

Related

Spring Boot, using oracle-ldap url through ssh tunnel on local machine

There are 3 machines:
local -> some remote server -> oracle db server (via ldap)
I want to set up datasource connection (in my spring boot app) to the oracle db.
There is no direct connectivity between local machine and the one with oracle db.
So, i'm using the ssh tunnel through remote server:
ssh -L 127.0.0.1:8081:some.ldap.host:389 user#remote.server.host
In application.yml file i'm using further url:
spring:
datasource:
url: jdbc:oracle:thin:#ldap://127.0.0.1:8081//srvcnm,cn=OracleContext,dc=yy,dc=xx,dc=com
And when my app trying to get db connection, im getting the following error:
Caused by: oracle.net.nt.TimeoutInterruptHandler$IOReadTimeoutException: Socket read timed out
at oracle.net.nt.TimeoutSocketChannel.handleInterrupt(TimeoutSocketChannel.java:254)
at oracle.net.nt.TimeoutSocketChannel.connect(TimeoutSocketChannel.java:103)
at oracle.net.nt.TimeoutSocketChannel.<init>(TimeoutSocketChannel.java:77)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:192)
... 126 common frames omitted
Whenever i'm deploying app on the remote server and enter "direct" url in application.yml the connection is being obtained without any timeouts, and the app works well.
jdbc:oracle:thin:#ldap://some.ldap.host:389//srvcnm,cn=OracleContext,dc=yy,dc=xx,dc=com
Does anyone know how to handle this? How to get connection from local machine?
I may do some thing like this, I am going to create file call ~/.ssh/config then add following
Host remoteserver1
User usermane
Hostname ip or host name
ForwardAgent yes
Host oracleserver
User username
Hostname some.ldap.host
Port 22
# ForwardAgent yes if you need to forward one more instance
LocalForward 8081 some.ldap.host:389
ProxyCommand ssh -q -W %h:%p remoteserver1
What this does is that when I attempt to connect to ssh oracleserver from remoteserver1, it connects to hopper and then proxies the SSH connection to port 22 on overthere (ie: SSH on oracleserver).
now to connect via ssh do following ssh oracleserver , as it will make ssh tunnel between your machine and oracleserver via remoteserver1. along with port forwarding.
The problem was in redirecting source connection request to another machine with oracle db itself (after ldap auth).
So, the request's path looked like:
1.local -> 2.remote server -> 3.ldap server -> 4.oracle db server
There wasn't connectivity between 1st and 4th machine as the tunnel was only between 1th and 3rd one.
So, you if you faced this issue, you may add one more ssh tunnel (First tunnel is for ldap server, second one for oracle db) and enrich your "etc/hosts" with oracle server's routing.
In my case the issue was in access restrictions. The oracle server is filtering sockets somehow and grants access to certain machines.

DB2 jdbc connection error Connection refused. ERRORCODE=-4499, SQLSTATE=08001

I have a new DB2 server (v10.5.0.3), and I can connect to the database locally just fine.
When trying to connect from a remote server using JDBC I am getting the "Connection refused. ERRORCODE=-4499, SQLSTATE=08001" error. Based on information found here https://www-304.ibm.com/support/docview.wss?uid=swg21403644 I have confirmed that
[db2inst1#db2 ~]$ db2set -all
[i] DB2COMM=TCPIP
[i] DB2AUTOSTART=YES
[g] DB2SYSTEM=db2.xxxx.com
[g] DB2INSTDEF=db2inst1
[g] DB2ADMINSERVER=xxxxxx
and
[db2inst1#db2 ~]$ db2 get database manager configuration | grep -i svce
TCP/IP Service name (SVCENAME) = 50001
SSL service name (SSL_SVCENAME) =
with these JDBC connection values
driver=com.ibm.db2.jcc.DB2Driver
url=jdbc:db2://db2.xxxxx.com:50001/TESTGEN
username=XXXXXXXX
password=XXXXXXX
I have verified that the firewall on the both servers have opened ports 50000 and 50001. I've run out of ideas, any help is greatly appreciated.
I had the same trouble... Its was caused by IPV6...
The URL connection point to localhost, resolved as ::1 (the IPV6 address of localhost) and DB2 server doens't listing IPV6 protocol.
I resolved by modify the c:\windows\system32\driver\etc\host file : I uncomment the line 127.0.0.1 locahost to force ipv4 resolution name of locahost... and it's works.
I hope that helps. (sorry for my English)
I had same problem, when I couldn't connect to my remote database with Data Studio Client and with DB2 CLP console. Make sure that you checked ping to your server and it is successful, you checked dbm cfg and you know svcename, tcpip port number, you checked ..System32\drivers\etc\services file and there is "svcename tcpip_port_number/tcp" in that file. So, while you get message in your db2diag.log ""TCPIP" protocol support was successfully started.", it isn't network problem. I opened ports on my server mashine: DB2 server tcpip port(svcename) and DB2 DAS tcpip port through the Firewall settings. I found help on this reference https://learn.microsoft.com/en-us/sql/reporting-services/report-server/configure-a-firewall-for-report-server-access?view=sql-server-ver16.
Be careful and consult with your system admin about security.
(Sorry for my English)))
It was indeed a network error. I'm not fully sure which fix was the most important but I made sure telnet was enabled and white listed the DB2 process in the RHEL firewall configuration.

Issues with connecting to sql server db via linux

Im trying to execute a jar file from linux.The jar contains java code for connecting to sql server. When I try to execute the jar, Im getting the below error
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host servername, port 1433 has failed. Error: "null. 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.".
The connect properties file seems to have a valid username/password. I have checked the sql server configuration manager and the TCP/IP protocol is enabled. Im able to execute the same jar file in winodws and the sql server connection is established fine without any issues. Please let me know the steps I have to take to get this issue resolved.
Any help on this is much appreciated. Thanks

Connecting to derby via I.P. Address fails

When I print the I.P. address of the system using InetAddress.getLocalHost(), I get user-VAIO/192.168.1.3 . Now, when I connect to derby using jdbc:derby://localhost:1527/mydatabase;create=true, it connects without any errors but when I connect the same using jdbc:derby://192.168.1.3:1527/mydatabase;create=true, it fails giving me the following exception:-
java.net.ConnectException : Error connecting to server 192.168.1.3 on port 1527 with message Connection refused: connect.
Any help will be appreciated.
When you start your Derby Network Server, you provide a value for the '-h' argument. You might not realize you are doing this, if you are using the packaged StartNetworkServer.bat file, but look inside the batch file, and you will see the -h argument there.
The batch file comes provided with the syntax '-h default' when you download Derby from the Apache website.
But you can change that, to say, for example, '-h 192.168.1.3', and then your Derby Network Server will accept connections that specify 'jdbc:derby://192.168.1.3/my/database'.
Note that if you want to accept such connections from other computers on the network, you will also have to adjust your Windows Firewall rules, as by default it will prevent such connections.

what would be the database URL of the mysql database that we access through phpMyAdmin?

I am writing a code that access a MySql database. The database is on a server that we access through our web-browser
Let's say,
URL: http://cbm.goo.com/phpMyAdmin
Username: username
Password: password
The above username and password are used to access the MySql database through a web-browser.
Q1. What would be database url of the database to be used in JDBC programming?
I tried the following url but it didn't work
jdbc:mysql://cbm.goo.com:3306/scores?user=username&password=password
========================== Edited ===================================
I am getting the following error:
Communications link failure
The last packet successfully received from the server was 1,267,163,244,109 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
Check that your internet connection is not going through some sort of firewall that is blocking access to port 3306.
Some companies have restricitions set on which ports can be used. Web servers use port 80 which is usually opened up to allow web browsing. Your MySQL server is using port 3306.
Using JDBC with MySQL quick start guide

Categories

Resources