如何将Java应用程序(Java代码)连接到cloudant? [英] how to connect a Java app ( java code ) to cloudant?

查看:81
本文介绍了如何将Java应用程序(Java代码)连接到cloudant?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在eclipse中使用了Java代码,并且已经完成了eclipse和IBM bluemix cloudant服务
之间所需的所有设置。我不确定如何更新代码以在eclipse
中启用cloudant有人请帮忙吗?

I've java code in eclipse and I've done all the set up required between eclipse and IBM bluemix cloudant service I am not sure how to update my code to enable cloudant in eclipse can someone please help ?

推荐答案

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

you need to add a piece of code in CloudantClient.java file under source directory of your project. Please add these lines in CloudantClient class:

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循环中。

you can also put this piece of code in a try catch loop as well.

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();
            }

我希望它能起作用!

这篇关于如何将Java应用程序(Java代码)连接到cloudant?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆