I have a question.
I'm following the sample8 on http://virtuoso.openlinksw.com/dataspace/doc/dav/wiki/Main/VirtJenaProvider.
In particular, I have this code:
package ExampleVirtuoso;
import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.rdf.model.RDFNode;
import virtuoso.jena.driver.*;
public class ExampleVirtuoso {
public static void main(String[] args) {
/* STEP 1 */
VirtGraph set = new VirtGraph("jdbc:virtuoso://localhost:1111", "dba", "dba");
/* STEP 2 */
System.out.println("\nexecute: CLEAR GRAPH <http://test1>");
String str = "CLEAR GRAPH <http://test1>";
VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(str, set);
vur.exec();
System.out.println("\nexecute: INSERT INTO GRAPH <http://test1> { <aa> <bb> 'cc' . <aa1> <bb1> 123. }");
str = "INSERT INTO GRAPH <http://test1> { <aa> <bb> 'cc' . <aa1> <bb1> 123. }";
vur = VirtuosoUpdateFactory.create(str, set);
vur.exec();
/* STEP 3 */
/* Select all data in virtuoso */
System.out.println("\nexecute: SELECT * FROM <http://test1> WHERE { ?s ?p ?o }");
Query sparql = QueryFactory.create("SELECT * FROM <http://test1> WHERE { ?s ?p ?o }");
/* STEP 4 */
VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create(sparql, set);
ResultSet results = vqe.execSelect();
while (results.hasNext()) {
QuerySolution rs = results.nextSolution();
RDFNode s = rs.get("s");
RDFNode p = rs.get("p");
RDFNode o = rs.get("o");
System.out.println(" { " + s + " " + p + " " + o + " . }");
}
System.out.println("\nexecute: DELETE FROM GRAPH <http://test1> { <aa> <bb> 'cc' }");
str = "DELETE FROM GRAPH <http://test1> { <aa> <bb> 'cc' }";
vur = VirtuosoUpdateFactory.create(str, set);
vur.exec();
System.out.println("\nexecute: SELECT * FROM <http://test1> WHERE { ?s ?p ?o }");
vqe = VirtuosoQueryExecutionFactory.create(sparql, set);
results = vqe.execSelect();
while (results.hasNext()) {
QuerySolution rs = results.nextSolution();
RDFNode s = rs.get("s");
RDFNode p = rs.get("p");
RDFNode o = rs.get("o");
System.out.println(" { " + s + " " + p + " " + o + " . }");
}
}
}
I have added to my build path this libraries:
virtjdbc3.jar
virt_jena.jar
Jena libs
but when I compile this code, I get this error:
Exception in thread "main" com.hp.hpl.jena.shared.JenaException: virtuoso.jdbc3.VirtuosoException: Connection failed: Connection refused: connect
at virtuoso.jena.driver.VirtGraph.<init>(VirtGraph.java:206)
at virtuoso.jena.driver.VirtGraph.<init>(VirtGraph.java:93)
at ExampleVirtuoso.ExampleVirtuoso.main(ExampleVirtuoso.java:10)
Caused by: virtuoso.jdbc3.VirtuosoException: Connection failed: Connection refused: connect
at virtuoso.jdbc3.VirtuosoConnection.connect(Unknown Source)
at virtuoso.jdbc3.VirtuosoConnection.connect(Unknown Source)
at virtuoso.jdbc3.VirtuosoConnection.<init>(Unknown Source)
at virtuoso.jdbc3.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at virtuoso.jena.driver.VirtGraph.<init>(VirtGraph.java:191)
... 2 more
I have tried to change
virt_jena.jar
with
virt_jena2.jar
, but I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: virtuoso/jdbc4/VirtuosoConnectionPoolDataSource
at virtuoso.jena.driver.VirtGraph.<init>(VirtGraph.java:70)
at virtuoso.jena.driver.VirtGraph.<init>(VirtGraph.java:92)
at ExampleVirtuoso.ExampleVirtuoso.main(ExampleVirtuoso.java:10)
Caused by: java.lang.ClassNotFoundException: virtuoso.jdbc4.VirtuosoConnectionPoolDataSource
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
I premise to be ignorant about the functionally of Virtuoso and I may omitted some initial step. I have downloaded the libraries on http://virtuoso.openlinksw.com/dataspace/doc/dav/wiki/Main/VOSDownload#Jena%20Provider
What am I doing wrong here?
This first exception tells you that you tried to connect with a system which doesn't host the needed services, so either your connection string is wrong or you need to start whichever service you need or check your firewall settings and such. "Connection refused" is pretty obvious some kind of configuration problem with the service you want to connect to.