使用在SPARQL查询中使用查询字符串外部声明的变量 - 使用JSP和Java Servlet [英] Using a variable declared outside the Query string inside a SPARQL Query- Using JSP and Java Servlet

查看:122
本文介绍了使用在SPARQL查询中使用查询字符串外部声明的变量 - 使用JSP和Java Servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个jsp页面。在索引页面中,我选择一个下拉值并将所选值作为url参数传递给SearchResults页面。

I have 2 jsp pages. In the index page I am selecting a dropdown value and passing the selected value as a url parameter to the SearchResults page.

http://localhost:8080/SearchResults.jsp?jobCat=InformationTechnology

我正在使用下面的代码捕获传递的参数 InformationTechnology 。查询应显示表单中所选值的结果。 (我选择的是职业类别,结果应该显示所选职位类别下的候选人)

I am capturing the parameter InformationTechnology passed using below code . The query should show results for the selected value in the form. (I am selecting a job category and the results should show the candidates under selected job category)

String jobCategory = request.getParameter("jobCat");

以下是我的查询

String queryString =
"Select ?a ?b"+
" Where { ...."+
" Filter (?a = "+ jobCategory  +")"+// jobCategory is the String variable 
" }";

但我收到ParseException错误。

But I am getting ParseException Error.

com.hp.hpl.jena.query.QueryParseException: Encountered " "in" "In "" at line 
1, column 559.
Was expecting one of:
<IRIref> ...
<PNAME_NS> ...
<PNAME_LN> ...
<VAR1> ...
<VAR2> ...
"exists" ...
"not" ...
"count" ...
"min" ...
"max" ...
"sum" ...
"avg" ...
"sample" ...
"group_concat" ...
"bound" ...
"coalesce" ...
"if" ...
"bnode" ...
"iri" ...
"uri" ...
"str" ...
"strlang" ...
"strdt" ...
"datatype" ...
"lang" ...
"langmatches" ...
"isURI" ...
"isIRI" ...
"isBlank" ...
"isLiteral" ...
"isNumeric" ...
"regex" ...
"sameTerm" ...
"RAND" ...
"ABS" ...
"CEIL" ...
"FLOOR" ...
"ROUND" ...
"CONCAT" ...
"SUBSTR" ...
"STRLEN" ...
"UCASE" ...
"LCASE" ...
"ENCODE_FOR_URI" ...
"CONTAINS" ...
"strSTARTS" ...
"strENDS" ...
"YEAR" ...
"MONTH" ...
"DAY" ...
"HOURS" ...
"MINUTES" ...
"SECONDS" ...
"TIMEZONE" ...
"TZ" ...
"NOW" ...
"MD5" ...
"SHA1" ...
"SHA224" ...
"SHA256" ...
"SHA384" ...
"SHA512" ...
"true" ...
"false" ...
<INTEGER> ...
<DECIMAL> ...
<DOUBLE> ...
<INTEGER_POSITIVE> ...
<DECIMAL_POSITIVE> ...
<DOUBLE_POSITIVE> ...
<INTEGER_NEGATIVE> ...
<DECIMAL_NEGATIVE> ...
<DOUBLE_NEGATIVE> ...
<STRING_LITERAL1> ...
<STRING_LITERAL2> ...
<STRING_LITERAL_LONG1> ...
<STRING_LITERAL_LONG2> ...
"(" ...
"!" ...
"+" ...
"-" ...

是否有另一种方法可以在SPARQL查询中使用字符串变量,就像在类似场景中一样。提前感谢

Is there an alternative way to use the string variable inside a SPARQL query like in similar scenario. Thanks in advance

推荐答案

我有一个解决这个问题的方法。
我用 regex 来获取结果

I have a solution for this issue. I used regex to obtain the result

"filter(regex(?a, \"" + jobCategory + "\"))"

这篇关于使用在SPARQL查询中使用查询字符串外部声明的变量 - 使用JSP和Java Servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆