简体   繁体   中英

VCAP_SERVICES return null

I have the next code to connect my app to a DB2 database:

public static Connection init() {
    String VCAP_SERVICES = System.getenv("VCAP_SERVICES");
    Connection con = null;
    if (VCAP_SERVICES != null) {
        JSONObject vcap;
        try {
            vcap = (JSONObject) JSON.parse(VCAP_SERVICES);
            if(vcap.get("sqldb") != null) {                 
                con = initSQLDataBase();
            }
        } catch(IOException ex) {
            ex.printStackTrace();
        }   
    }
    return con;
}

My problem is that it never do the if because System.getenv("VCAP_SERVICES") returns always null.

The VCAP_SERVICES exists in Bluemix and I can connect my database in the Database Development Plugin for Eclipse, so I don't know what is wrong in my code.

Can someone helps me?

Thank you very much and sorry by my poor English.

[EDIT]: The problem is solved. It was by a problem elsewhere in the code. Sorry.

Yes, doesn't look like you have a key defined to obtain SQLDB. There's a very detailed code snippet at the link below that shows you how to parse vcap services:

https://www.ng.bluemix.net/docs/services/SQLDB/index.html#parse-vcap-in-java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM