You could call https://docs.marklogic.com/sem:sparql through an XCC 
moduleInvoke, something like this:

xquery version "1.0-ml";
(: sparql.xqy :)
import module namespace sem="http://marklogic.com/semantics"; 
  at "/MarkLogic/semantics.xqy" ;
(: Add more variables to support bindings, etc. as needed :)
declare variable $SPARQL as xs:string external ;
sem:sparql($SPARQL)
(: end :)

Then in Java:

Session session = contentSource.newSession("mydatabase");
Request request = session.newModuleInvoke("sparql.xqy");
request.setNewStringVariable('SPARQL', mySparqlQuery);
// add more variables to support bindings, etc. as needed.
ResultSequence rs = session.submitRequest(request);
while (rs.hasNext()) {
    ResultItem item = rs.next();
    // handle the item
}
session.close();

Wrap that up in a utility class, parameterize it as needed, and you'll never 
have to think about it again.

-- Mike

On 5 Jun 2014, at 09:43 , Marc Limotte <[email protected]> wrote:

> Hi.
> 
> I'd like to run a SPARQL query from Java.  I've found various bits of 
> documentation (including 
> http://developer.marklogic.com/learn/semantics-exercises/sparql-101).  But 
> the docs all seem to cover running SPARQL from the console or maybe REST or 
> Xquery.  Can someone point me in the right direction for running a SPARQL 
> query in Java?  
> 
> I don't need detailed instructions, just an overview or a pointer to the 
> right documentation.
> 
> thanks for any help,
> Marc
> 
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to