jpabene
jpabene

Reputation: 159

Connecting to an OpenShift MySQL database with Eclipse

I just have a quick question to make sure that I'm doing everything right before proceeding with my web application.

I've written my web app in Eclipse and am hosting it through OpenShift. Using OpenShift, I've also set up a MySQL database (I had previously been using Derby for the local stuff, but I've decided to move to MySQL because OpenShift does not accommodate Derby).

I want to be able to 1) connect to the MySQL and create tables, etc. and 2) connect to the MySQL within my servlets. My question here primarily concerns the first order of business.

When I call port-forward, I get:

Service Local               OpenShift
------- -------------- ---- -----------------
java    127.0.0.1:8080  =>  127.11.150.1:8080
mysql   127.0.0.1:3306  =>  127.11.150.2:3306

Now, when I navigate to Database Development in Eclipse and go to create a new database, when type in:

jdbc:mysql://127.11.150.2:3306/<my-app-name>

... for the URL, along with my username and password (and where is the name of my app), the ping fails. However, for:

jdbc:mysql://127.0.0.1:3306/<my-app-name>

Everything works just peachy.

My question is this: if I use the local IP address, will my servlets still be able to access the database when Eclipse is shut down and the port-forward is closed? If not, what do I need to do to edit and update the MySQL database through Eclipse?

Thanks in advance!

Upvotes: 0

Views: 776

Answers (1)

user2953119
user2953119

Reputation:

The ip-address you got from the openshift ssh-console (or from your OpenShift web profile, doesn't matter here) is a strictly local ip-address used for your application. You may probably deploy some web-admin interface (like phpMyAdmin) to communicate with your OpenShift database from outside, but that's not desirable for some security reasons. In a normal way your database is allowed for access only through other openshift artifacts.

Openshift, in turn, provides some predefined environment variables with databases urls and so forth. You could check them out in your ssh-console.

So, if you set the appropriate configuration (corresponing to the OpenShift database) at your OpenShift web-container then yes, it will work fine.

Upvotes: 1

Related Questions