System.getenv() returns null

余生颓废 提交于 2019-12-12 04:49:58

问题


I'm trying through a Java applet to connect to a Mysql database set up on OpenShift.

String dbHost = System.getenv("OPENSHIFT_MYSQL_DB_HOST");
String dbPort = System.getenv("OPENSHIFT_MYSQL_DB_PORT");

both of those strings return NULL when the application is online.
If I connect through ssh to the database everything seems to be working fine, I can see the database and I can work on it.

What am I missing?


回答1:


1) what does echo $OPENSHIFT_MYSQL_DB_HOST give if you connect via ssh? You might use this as a default (for starters)

dbHost = System.getenv("OPENSHIFT_MYSQL_DB_HOST") != null 
         System.getenv("OPENSHIFT_MYSQL_DB_HOST") : "defaultvalue";

2) try to export OPENSHIFT_MYSQL_DB_HOST=yourhostname



来源:https://stackoverflow.com/questions/27431971/system-getenv-returns-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!