helun/Ektorp

Retrieve data from cloudant database using java liberty(java servlet program)

Opened this issue · 1 comments

I am facing problem in my project:

Problem: Need to get the last value inserted in a table in cloudant database using java liberty (java servlet program). but I get a program which retrieve the data of a specific id.(code below)I need to print the last value inserted in cloudant database in an android application

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

}
}
i try View query but

           ViewQuery q = createQuery("recent").limit(1).descending(true).key(keys).includeDocs(true); 
            ViewResult vr = dbconnector1.queryView(q); 
            List<Row> rows = vr.getRows(); 
            for (Row row : rows) 
            { 
              a = row.getKey().tostring();; 
              b = row.getValue().tostring(); 
            }

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/pipeline/a77663db-cbef-4367-b7f1-d1ec2024871e/src/main/java/wasdev/sample/servlet/Servlet_iot4.java:[123,82] cannot find symbol
symbol: variable keys
location: class wasdev.sample.servlet.Servlet_iot4
[ERROR] /home/pipeline/a77663db-cbef-4367-b7f1-d1ec2024871e/src/main/java/wasdev/sample/servlet/Servlet_iot4.java:[123,30] cannot find symbol
symbol: method createQuery(java.lang.String)
location: class wasdev.sample.servlet.Servlet_iot4
[ERROR] /home/pipeline/a77663db-cbef-4367-b7f1-d1ec2024871e/src/main/java/wasdev/sample/servlet/Servlet_iot4.java:[124,17] cannot find symbol
symbol: class ViewResult
location: class wasdev.sample.servlet.Servlet_iot4
[ERROR] /home/pipeline/a77663db-cbef-4367-b7f1-d1ec2024871e/src/main/java/wasdev/sample/servlet/Servlet_iot4.java:[125,22] cannot find symbol
symbol: class Row
location: class wasdev.sample.servlet.Servlet_iot4
[ERROR] /home/pipeline/a77663db-cbef-4367-b7f1-d1ec2024871e/src/main/java/wasdev/sample/servlet/Servlet_iot4.java:[126,22] cannot find symbol
symbol: class Row
location: class wasdev.sample.servlet.Servlet_iot4

I got this error i had add

import org.ektorp.ViewQuery;
import org.ektorp.support.View;

but no use so please help me...
I am using Java Liberty, devOps (git), cloudant

Hi, it seems you have a compilation issue, that has nothing to do with Ektorp nor Cloudant.

Code samples in the Ektorp documentation do not explicitly state imports, but you have to use them for your code to compile.