St.Antario
St.Antario

Reputation: 27375

How to connect to a database in openshift?

I've creted a new database in openshift:

PostgreSQL 9.2 database added.  Please make note of these credentials:

   Root User: xxxxxxxxx
   Root Password: xxxxxxxxxx
   Database Name: xxxxxxxx

Connection URL: postgresql://$OPENSHIFT_POSTGRESQL_DB_HOST:$OPENSHIFT_POSTGRESQL_DB_PORT

I need to connect to the database manually via psql. How can I do that? I mean, how can I enquire that variable?

Upvotes: 1

Views: 1887

Answers (1)

timo.rieber
timo.rieber

Reputation: 3867

You need to read environment variables in Java like this:

String envVar = System.getenv("OPENSHIFT_ENV_VAR");

In your case:

String dbHost = System.getenv("OPENSHIFT_POSTGRESQL_DB_HOST");
String dbPort = System.getenv("OPENSHIFT_POSTGRESQL_DB_PORT");

Read more at the Openshift docs, "Using Environment Variables".

Upvotes: 2

Related Questions