I am trying to make a query using Jena ARQ as follows:

static public final String NL = System.getProperty("line.separator") ;

//some codes

    String prolog = "PREFIX rdf: <"+ RDF.getURI()+"> 
    PREFIX rdfs: <"+RDFS.getURI()+"> 
    PREFIX myproject:<http://www.myproject.com/ontologies/myproject.owl#>" ;

    String queryString = prolog + NL 
+ "SELECT ?individu WHERE {
      ?individu rdf:type myproject:Plant. 
      ?individu myproject:height ?height.  
      FILTER(?height <= 6.0). 
     ?individu myproject:diameter ?diameter. 
     FILTER(?diameter = 0.5)} 
    ORDER BY ?individu
}" ;

//some codes

Using this code my program works well. As we can see that I use constant filter values for height and diameter (6.0 and 0.5 respectively). However actually what I want is not a constant filter values. Instead I want variable filter values. This is similar to PreparedStatement in MySQL. I need this because the query must change dynamically based on user input. So, my question is: how can I make a query using variable filter value? Thanks.

asked 12 Jan, 06:15

Iman's gravatar image

Iman
111
accept rate: 0%

edited 17 May, 10:35

fellahst's gravatar image

fellahst
2.6k29


(answer copied over from users@jena.apache.org)

See ParameterizedSparqlString or QueryExecutionFcatory.create(... QuerySolution)

link

answered 12 Jan, 12:23

AndyS's gravatar image

AndyS ♦
10.0k27
accept rate: 33%

I personally think that in this situation if you have to make query using variable filter value you can build the query dynamically.

same day delivery

link

answered 17 May, 05:27

msmith's gravatar image

msmith
72
accept rate: 0%

edited 17 May, 05:33

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×429
×115
×38
×14

Asked: 12 Jan, 06:15

Seen: 362 times

Last updated: 17 May, 10:35