1

I am really stuck at this...I am trying to convert Result Set into string and this is my code :

QueryExecution qExec = QueryExecutionFactory.create(s, ds) ;
       ResultSet rs = qExec.execSelect() ;
       //String x=rs.toString();
       String[] arr = null;

        while (rs.next()) {
            String em = (String)rs.getString(0);
           arr = em.split("\n");
           for (int i =0; i < arr.length; i++){
              subjectoutput.setText(arr[i]); 
           }
       }

and it gives error:

JavaApplication2.java:137: error: incompatible types
            while (rs.next()) {
                          ^
  required: boolean
  found:    QuerySolution
JavaApplication2.java:138: error: cannot find symbol
                String em = (String)rs.getString(0);
                                      ^
  symbol:   method getString(int)
  location: variable rs of type ResultSet
2 errors

my query result is this:

    ----------------------------
| x                                           
================================================
| <<SEMA-CR-3-4MHV9RJ@bounce.oracle-mail.com>> |
------------------------------------------------
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
cooljohny
  • 656
  • 5
  • 13
  • 31

1 Answers1

2

It looks like you're trying to use ResultSet as if it were from JDBC. But you're using Jena ARQ here. This isn't a JDBC implementation and it doesn't follow that API. QueryExecution is here, and ResultSet is here.

For this ResultSet object, you should call hasNext() to see if there is another record, and next() to fetch the record. So your loop might look more like this:

while (rs.hasNext()) {
    QuerySolution qs = rs.next();
    ... // Do something with qs
}

ResultSet.getString(int) is a JDBC function, and there's no such function on either ResultSet or QuerySolution, so I couldn't tell you exactly how to get the information that you want out of the result set.

Kenster
  • 23,465
  • 21
  • 80
  • 106
  • that helped me a lot!! but I am still don't know how to convert it to string? – cooljohny May 25 '14 at 15:08
  • 2
    Take a look at the API documentation. – AndyS May 25 '14 at 15:34
  • @user3654540 A result set provides a set of query solutions. Each solution binds a set of variables. You'd need to get the result for a particular variable from a query solution, and then convert that to a string. The documentation that Kenster linked to should be descriptive enough to figure out how to do this. – Joshua Taylor May 25 '14 at 17:01