cooljohny
cooljohny

Reputation: 706

How to perform delete query in jena sparql?

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!!

Upvotes: 0

Views: 972

Answers (1)

Joshua Taylor
Joshua Taylor

Reputation: 85883

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.

Upvotes: 3

Related Questions