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 '13, 06:15

Iman's gravatar image

Iman
111
accept rate: 0%

edited 17 May '13, 10:35

fellahst's gravatar image

fellahst
3.3k29


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

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

permanent link

answered 12 Jan '13, 12:23

AndyS's gravatar image

AndyS ♦
13.6k37
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

permanent link

answered 17 May '13, 05:27

msmith's gravatar image

msmith
72
accept rate: 0%

edited 17 May '13, 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

Question tags:

×617
×164
×46
×24

question asked: 12 Jan '13, 06:15

question was seen: 948 times

last updated: 17 May '13, 10:35