Access database in Openshift

Asked

Viewed 801 times

6

I deployed a project on OpenShift, I used a Cartridge to create a bank Mysql soon after the creation of the bank appear this information:

Mysql 5.5 database Added. Please make note of These credentials:

Root User: adminhtK8LZq Root Password: shKekKGKhHEH Database Name: Obolt

Connection URL: mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/

You can Manage your new Mysql database by also embedding phpmyadmin. The phpmyadmin username and password will be the same as the Mysql credentials above.

But when I set up mine hibernate.cfg with this data the database is not created in the OpenShift.

Hibernate.cfg:

<!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/oraculo </property>
        <property name="connection.username">adminhtK8LZq</property>
        <property name="connection.password">shKekKGKhHEH</property>
        ...

I have to pass some value in place of this URL, I tried to pass the ip that appears in phpMyAdmin but it didn’t work.

  • Any reason for the pass given by Openshift and the pass on Hibernate.cfg to be different?

  • And why would Hibernate create the bank? It is only able to create or update the tables in one existing bank. To do so, use <property name="hibernate.hbm2dll.auto">create</property>, or update in place of create.

  • The bank already exists and I am using create

  • You can access your Cartridge via ssh and see if you can connect using these credentials?

  • Yes, I can access using these credentials by phpMyAdmin as well

  • vc has arrived put ip and port that so there in phpmyadmin there in mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/ and make the deploy again ?

  • I tried yes, but it’s still the same. I’m going to do one more test.

  • I just tried again and nothing, when access to URL that would query the database is not created. URL: http://sistemaoraculo-projetounimed.rhcloud.com/usuario/usuarios/consultar

Show 3 more comments

1 answer

4


I work with Openshift. I’ll explain to you what happens and how I usually work on this kind of thing.

Openshift has some variables to make your life easier. $OPENSHIFT_MYSQL_DB_HOST, $OPENSHIFT_MYSQL_DB_PORT and others are set there in openshift.

Below is an example of how I recover variables and connect using JDBC:

this.openShiftDbHost = System.getenv("OPENSHIFT_MYSQL_DB_HOST");
this.openShiftDbPort = System.getenv("OPENSHIFT_MYSQL_DB_PORT");
this.openShiftDbUser = System.getenv("OPENSHIFT_MYSQL_DB_USERNAME");
this.openShiftDbPassword = System.getenv("OPENSHIFT_MYSQL_DB_PASSWORD");
conexao =  DriverManager.getConnection("jdbc:mysql://"+this.openShiftDbHost+":"+this.openShiftDbPort+"/mydb?user="+this.openShiftDbUser+"&password="+this.openShiftDbPassword);

In the case of Hibernate I do the following coniguration:

<property name="url" value="jdbc:mysql://${OPENSHIFT_MYSQL_DB_HOST}:${OPENSHIFT_MYSQL_DB_PORT}/${OPENSHIFT_APP_NAME}" />
<property name="username" value="${OPENSHIFT_MYSQL_DB_USERNAME}" />
<property name="password" value="${OPENSHIFT_MYSQL_DB_PASSWORD}" />
  • I’ll try here

  • I did the way that Voce said but it still didn’t work, when I try to access the URL of this API that makes a query in the bank, the same is not created. http://sistemaoraculo-projetounimed.rhcloud.com/usuario/usuario/1

  • Just a doubt, I have to change the values, for example: OPENSHIFT_MYSQL_DB_HOST to the bank way?

  • No need to change anything not expensive. To access the database outside the application you need to use the Phpmyadmin provided in Openshift.

  • I tried and still it didn’t work, another strange thing I noticed, when I make changes to the index.html page and give commit nothing changes, however if I clone the project it comes with the changes made, I thought that the commit/push was not working.

  • Problem solved, commit was not working anyway

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.