eclipse - How to Count the number of rows in Sparql Query -
i working in eclipse , using 2 java files: admin.java , semanticsearch.java. through the admin.java logging in , checking if username , password existing in rdf file. function of login in admin.java calls semanticsearch.java runs sparql query. query giving me answer in console of eclipse , onto file. job give answer admin.java either returning value or counting rows , sending value admin.java. if number of rows 1 means username , password match , can allow user login.
but not able so. have tried using count(), count() cnt, tried int res=results.next. nothing seems help.
i pasting code below:
admin.java
semanticsearch semsearch = new semanticsearch(request.getsession()); semsearch.loaddata(realpath + rdfdatasourcefile1); semsearch.searchforuser(response.getoutputstream(),null, username, password);
in semanticsearch.java
public void searchforuser(outputstream out, string xslfile1, string username, string password) { string prolog = "prefix kb:<"+vuser.geturi()+">"; system.out.println("search user in semantic search.java"); string querystring1 = prolog +"\n" +"select * " +"where {" +"?x kb:uname ?username. ?x kb:password ?password. ?x kb:interest ?interest. " +"filter regex(?username, \"" +username +"\")}"; system.out.println(querystring1); query query=queryfactory.create(querystring1); queryexecution qexec = queryexecutionfactory.create(query, model); resultset results1 = qexec.execselect(); --> here 2 rows printed int res=results1.getrownumber(); system.out.println(results1); -->here answer 0 resultsetformatter.out(results1); resultsetformatter.out(out, results1); system.out.println(res); try { if (xslfile1 != null) { out.write(resultsetformatter.asxmlstring(results1, xslfile1).getbytes("utf-8")); system.out.println(results1); system.out.println(xslfile1); system.out.println("i in if"); } else { out.write(resultsetformatter.asxmlstring(results1).getbytes( "utf-8")); system.out.println("i in else"); } } catch (ioexception e) { e.printstacktrace(); } }
please help, struggling week, regards, archana.
in sparql 1.1, may supported in triplestore you're using, syntax is:
select (count(*) ?count) { ... }
you should integer returned in ?count column, number of results.
Comments
Post a Comment