The correct endpoint URL for Wikidata is https://query.wikidata.org/sparql - you are missing the last bit.
In addition, I noticed a few crashes in your code. First of all, you do this:
SPARQLConnection sparqlConnection = new SPARQLConnection(sparqlRepository);
It should be as follows:
RepositoryConnection sparqlConnection = sparqlRepository.getConnection();
Always retrieve your connection object from the Repository object using getConnection() - this means that resources are shared, and Repository can close dangling connections if necessary.
Secondly: you cannot print the result of the query as follows:
System.out.println("Result for tupleQuery" + tupleQuery.evaluate());
If you want to print the result before System.out , you should do something like this:
tupleQuery.evaluate(new SPARQLResultsTSVWriter(System.out));
Or (if you want to tune the result a little more):
for (BindingSet bs : QueryResults.asList(tupleQuery.evaluate())) { System.out.println(bs); }
For what it's worth - with the above changes, the request request is executed, but it seems that your request is too "heavy" for Wikidata - at least I got a timeout error from the server. Try a simpler query and you will see that the code is working.
source share