0

This question might sound lame but I am really confused...This is my code for normal query :

public class test4query extends Object {
    public static String[] arr=new String[30];
    public  void  mai (String s) {
        String directory = "EMAILADDRESS" ;
        Dataset ds = TDBFactory.createDataset(directory) ;
        ds.begin(ReadWrite.READ) ;
        Model model = ds.getDefaultModel() ;

        QueryExecution qExec = QueryExecutionFactory.create(s, ds) ;
        int i=0;
        try{
             ResultSet rs = qExec.execSelect() ;
             String x=rs.toString();

             while (rs.hasNext()) {
                 QuerySolution qs = rs.next();
                 String rds;
                 if(qs.get("x")!=null) {
                    rds = qs.get("x").toString();
                 } else {
                    rds="hi";
                 }
                 if(rds==null) {
                    break;
                 }
                 System.out.println(rds);
                 arr[i] = rds;
                 i++;   
             }
        } finally
             {qExec.close() ;
             ds.commit();
             ds.end();
        }

    }
}

But this does not work for delete queries ..It shows error :

Was expecting one of:
    "base" ...
    "prefix" ...
    "select" ...
    "describe" ...
    "construct" ...
    "ask" ...

I know some changes need to be made for update queries?Can somebody give some hint?Any link will be helpful!!

cooljohny
  • 656
  • 5
  • 13
  • 31

1 Answers1

3

SPARQL Query and SPARQL Update are different languages, and there are different factories for parsing them. QueryFactory is for the SPARQL 1.1 Query Language. For the SPARQL 1.1 Update, you need to use UpdateFactory.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • I basically want to delete triples? what can I use?can you provide some link? – cooljohny Jun 23 '14 at 19:00
  • The answer contains links to the syntax for deleting from a dataset, & a link to the Javadoc for the jena API for running those. The changes to your code should be minimal. – Joshua Taylor Jun 23 '14 at 19:39
  • 1
    @cooljohny If you think that there's some other error in your code or in your update, you'll need to show them. sparql.org has an [update validator](http://sparql.org/update-validator.html) that you can use to check whether your update is legal. You haven't shown it in your question, so the rest of us have no idea whether it is or not. Your question does not contain a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Joshua Taylor Jun 24 '14 at 14:35