System.getenv() 返回 null [英] System.getenv() returns null
本文介绍了System.getenv() 返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过 Java 小程序连接到在 OpenShift 上设置的 Mysql 数据库.
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");
当应用程序在线时,这两个字符串都返回 NULL.
如果我通过 ssh 连接到数据库,一切似乎都运行良好,我可以看到数据库并可以对其进行处理.
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.
我错过了什么?
推荐答案
1) 如果您通过 ssh 连接,echo $OPENSHIFT_MYSQL_DB_HOST
会给出什么?您可以将其用作默认设置(对于初学者)
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) 尝试导出 OPENSHIFT_MYSQL_DB_HOST=yourhostname
这篇关于System.getenv() 返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文