Ibm cloud 使用java liberty(java servlet程序)从cloudant数据库检索数据

Ibm cloud 使用java liberty(java servlet程序)从cloudant数据库检索数据,ibm-cloud,cloudant,Ibm Cloud,Cloudant,我面临的问题是: 问题:需要使用JavaLiberty(JavaServlet程序)获取插入cloudant数据库表中的最后一个值。但我编写了一个程序来检索特定id的数据(下面的代码),我需要在android应用程序中获取插入cloudant数据库的最后一个值 @Resource(name = "couchdb/myCloudant") protected CouchDbInstance mydb ; @Override protected void doGet(HttpServletReq

我面临的问题是:

问题:需要使用JavaLiberty(JavaServlet程序)获取插入cloudant数据库表中的最后一个值。但我编写了一个程序来检索特定id的数据(下面的代码),我需要在android应用程序中获取插入cloudant数据库的最后一个值

@Resource(name = "couchdb/myCloudant")
protected CouchDbInstance mydb ;


@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

     String dbname1 = "Tempdb";
     String dbname2 = "pulsedb";

   try {

    CouchDbConnector dbconnector1 = mydb.createConnector(dbname1, true);


            InputStream s1 = dbconnector1.getAsStream("2");
   // here passing the id 2 in cloudant this will return the document of id 2

            BufferedReader reader1 = new BufferedReader(new InputStreamReader(s1));
            StringBuilder out1 = new StringBuilder();
            String line1;
            while ((line1 = reader1.readLine()) != null) {
                out1.append(line1);
            }
           // response.getWriter().print();
            String ss1 = out1.toString();
   }
 }

要在数据库中修改最后一个文档,需要使用changes提要。您可以找到更改提要的文档


您还应该使用
since
query string参数,这样您就不会读取每个请求的全部更改提要。

什么意思,“获取程序”?您是否试图获取最后一个文档id以便可以将其递增,递增的值将成为下一个文档id?如果是这样的话,cloudant将无法实现这一点。如果您想要自动递增字段,则需要使用cloudant的另一种技术,如redis。不,我需要将最后一个值插入到android应用程序的数据库中。我需要使用Bluemix中的Java liberty应用程序(Java servlet程序)获取最后一个文档。是否可能?我不熟悉该应用程序。但就像我说的。您可以向更改提要发出请求。请参阅所选库的文档以执行此操作,或发出原始HTTP请求以调用更改FED。