How does local Spring app access mysql on OpenShift? - java

I am building a local Spring app to access the database I created on OpenShift at 127.2.xx.yy/eetom:3306. So I created this propery in Beans.xml.
<property name="url" value="jdbc:mysql://127.2.xx.yy:3306/eetom"/>
but I got exceptions such as
Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
and
The driver has not received any packets from the server
So I changed the ip to localhost and used OpenShift rhc to create port forwarding. And the rhc showed that the ip I put originally and the port are exactly used for port forwarding. That method workded.
Question:
What is the right way to access the mysql diectly without port forwarding?

Someone helped me on this before, it's from OpenShift: OpenShift does not support direct connectivity to an embedded database on non-scalable applications.

Related

Wildfly Datasource via VPN to MS SQL Server

currently, I am facing some odd behavior.
I have a Java EE Web Application that I am deploying to a wildfly server. This Java EE Application needs a database to which we need to connect via vpn. We are using OpenVPN. When I am using SSMS I have no problems connecting to the database. When I am using pure JDBC, there also is no problem.
But if I am creating a datasource in wildfly (and I am using the exact same jdbc connection url) it does not working. I am using the wildfly admin ui and click the test-button.
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 10.1.115.51, port 1433 has failed. Error: "connect timed out. 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.".
I mean, the stack trace is pretty clear. However, the connection should be possbile as I connect via ssms and pure jdbc. Just wildfly datasource is not working.
Furhtermore, I have installed a MS SQL Server on the same mashine the wildfly is running on and using this MS SQL instance the datasource is working fine.
The jdbc url connection url is the following:
jdbc:sqlserver://< ip >:1433;databaseName=projdat;user= ** ;password= **
I have compared the jdbc url connection urls multiple times. Both in the pure jdbc and in the datasource they are the same.
Does anybody have any ideas? Is possible that I need to configure openvpn in a special way that wildfly can connect or do I need to configure Wildfly to be able to connect via vpn. Or do I have to configure the MS SQL Server in special way?
Version of MS SQL Server: 12
Version Wildfly: 19.0.0.Final
SQL Server driver: mssql-jdbc-8.2.2.jre8.jar
I apreciate any hint or advise.
Apparently, I was using an older version of Wildfly (in fact, it was wildfly 16). After I upgraded to Wildfly 19, it is now working. However, I have no clue why it was not working with wildfly 16.

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

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!

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.

Why JDBC cant connect to local Mysql Server

I have a machine with CentOS and mysql server on it (let's call it 'Server'). And another(my desktop) machine with Debian (let's call it 'Desktop'). I tried to launch java program on Desktop machine. Application connects to Server's mysql database without any troubles.
When I finished development of this application (it's still works and connects to DB well) I tried to deploy this app to Server machine. I'v built it the app on the server and tried to launch, using database, which still hosted on Server machine. So now it seems to be local database for my application. But it fails during connection to DB using Server IP address or "localhost" or 127.0.0.1. I have only:
java.sql.SQLException: null, message from server: "Host '82.192.90.179' is not allowed to connect to this MySQL server".
In my.cnf file on Server I've set "bind-address=0.0.0.0".
PS:The most interesting thing, I do everything on server using ssh, and if I try to connect to database with "mysql" console tool, it connects OK either with -h82.192.90.179 and without -h option(seems to be localhost as a dafault)
To know it is permission issue try GRANT ALL ON . TO 'someuser'#%;
http://dev.mysql.com/doc/refman/4.1/en/grant.html
Then modify the above statement by replacing % with '82.192.90.179' should work.
If you feel difficult to connect JDBC means try using mysql workbench MySQL WORKBENCH
1.Make sure you have to host your server code to local server or public server
2.If you host Local Server means it will not work
3.Make sure your server is alive or not
DB_URL = "jdbc:mysql://localhost:portnumber/databasename"
eg.DB_URL = "jdbc:mysql://localhost:3306/cmes"
Maintain Your Session configuration like this in your server side in Web.xml
<session-config>
<session-timeout>-1</session-timeout>
</session-config>

The Network Adapter could not establish the connection when connecting with Oracle DB

When trying to connect with a remote Oracle database via JDBC I receive the following exception:
java.sql.SQLRecoverableException: IO-fout: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:419)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
at java.sql.DriverManager.getConnection(DriverManager.java:322)
at java.sql.DriverManager.getConnection(DriverManager.java:358)
The following is my set-up:
Database: Oracle 10g Release 2 Standard Edition
JDBC library: ojdbc6.jar
JDBC driver: oracle.jdbc.driver.OracleDriver
JDBC URL: jdbc:oracle:thin:#9.2.2.2:1521:ORCL where ORCL is database's SID
JDBC User/pwd: Correct username / password
Strange about this problem is that the connection works just fine when I work from work. When I try to connect however from home via an AT&T VPN connection, it doesn't work.
I have confirmed that I can reach the IP address and have also telnetted the ip on port 1521, which works just fine. Connecting to the datasource from a local WebLogic Application Server also works alright. Furthermore, when trying to connect to the database via sqldeveloper I can also reach the database.
I need to reach the database however from a standalone application (for testing purposes). Does anyone have an idea why this problem occurs? And whether there are alternatives for connecting to a remote Oracle Database, alternatives which sqldeveloper and weblogic perhaps use?
Here's an excerpt of the code attempting to connect with the database:
public static void main(String args[]) throws ClassNotFoundException, SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:#9.2.2.2:1521:ORCL", "user", "pwd");
}
When a client connects to an Oracle server, it first connnects to the Oracle listener service. It often redirects the client to another port. So the client has to open another connection on a different port, which is blocked by the firewall.
So you might in fact have encountered a firewall problem due to Oracle port redirection. It should be possible to diagnose it with a network monitor on the client machine or with the firewall management software on the firewall.
If it is on a Linux box, I would suggest you add the database IP name and IP resolution to the /etc/hosts.
I have the same error and when we do the above, it works fine.
Take a look at this post on Java Ranch:
http://www.coderanch.com/t/300287/JDBC/java/Io-Exception-Network-Adapter-could
"The solution for my "Io exception: The Network Adapter could not establish the connection" exception was to replace the IP of the database server to the DNS name."
I had similar problem before. But this was resolved when I started using hostname instead of IP address in my connection string.

Categories

Resources