问题
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