OpenShift 3: How To Access POSTGRESQL POD Environment Variables Using Java? -


i have java webapp running on tomcat.

i have created 3 environment variables in myapp deployment:

my_env_var_1=dbuser my_env_var_2=dbpassword my_env_var_3=dbname 

i can these values using standard java code:

myenvvar1 = system.getenv("my_env_var_1"); myenvvar2 = system.getenv("my_env_var_2"); myenvvar3 = system.getenv("my_env_var_3"); 

i used 'normal java' code connect database:

connection = drivermanager.getconnection("jdbc:postgresql://" + postgresqlservicehost + ":" + postgresqlserviceport + "/" + myenvvar3, myenvvar1, myenvvar2);

so, can connect database successfully.

the problem is:

i can see (in web console) cannot values 3 environment variables in postgresql deployment:

postgresql_user postgresql_password postgresql_database 

using 'normal' system.getenv("postgresql_user"); not work.

so, please can tell me how access values of these 3 postgresql pod environment variables using java code?

so, simple answer is:

you manually add following 3 environment variables deployment environment of application accessing database.

postgresql_user postgresql_password postgresql_database 

you must in same way see them in postgresql deployment environment.

it simple...

in java app:

string postgresqlservicehost = system.getenv("postgresql_service_host"); string postgresqlserviceport = system.getenv("postgresql_service_port"); string postgresqldatabase = system.getenv("postgresql_database"); string postgresqluser = system.getenv("postgresql_user"); string postgresqlpassword = system.getenv("postgresql_password");  connection connection = drivermanager.getconnection("jdbc:postgresql://" + postgresqlservicehost + ":" + postgresqlserviceport + "/" + postgresqldatabase, postgresqluser, postgresqlpassword); 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -