gpt4 book ai didi

cloudant - 如何将 Java 应用程序(java 代码)连接到 cloudant?

转载 作者:行者123 更新时间:2023-12-01 19:19:01 28 4
gpt4 key购买 nike

我在 eclipse 中有 java 代码,并且已经完成了 eclipse 和 IBM bluemix cloudant 服务之间所需的所有设置我不知道如何更新我的代码以在 Eclipse 中启用 cloudant有人可以帮忙吗?

最佳答案

您需要在项目源目录下的CloudantClient.java文件中添加一段代码。请在 CloudantClient 类中添加以下行:

String VCAP_SERVICES = System.getenv("VCAP_SERVICES");
JSONObject vcap;
vcap = (JSONObject) JSONObject.parse(VCAP_SERVICES);
cloudant = (JSONArray) vcap.get("cloudantNoSQULDB");
cloudantInstance = (JSONObject) cloudant.get(0);
cloudantCredentials = (JSONObject) cloudantInstance.get("credentials");

您也可以将这段代码放入 try catch 循环中。

try {
String VCAP_SERVICES = System.getenv("VCAP_SERVICES");
JSONObject vcap;
vcap = (JSONObject) JSONObject.parse(VCAP_SERVICES);
cloudant = (JSONArray) vcap.get("cloudantNoSQULDB");
cloudantInstance = (JSONObject) cloudant.get(0);
cloudantCredentials = (JSONObject) cloudantInstance.get("credentials");
}
catch (IOException e) {
e.printStackTrace();
}

希望它能成功!

关于cloudant - 如何将 Java 应用程序(java 代码)连接到 cloudant?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27719335/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com