我有一个问题。
我正在关注http://virtuoso.openlinksw.com/dataspace/doc/dav/wiki/Main/VirtJenaProvider上的示例8。
特别是,我有这段代码:
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 + " . }");
}
}
}
我已将此库添加到我的构建路径中:
virtjdbc3.jar
virt_jena.jar
Jena libs
但是当我编译这段代码时,我收到了这个错误:
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
我试图改变
virt_jena.jar
带
virt_jena2.jar
,但是我收到了这个错误:
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
我的前提是对Virtuoso的功能无知,我可能省略了一些初步步骤。 我已经在http://virtuoso.openlinksw.com/dataspace/doc/dav/wiki/Main/VOSDownload#Jena%20Provider
上下载了这些库我在这里做错了什么?
答案 0 :(得分:5)
第一个例外告诉您,您尝试连接的系统没有托管所需的服务,因此您的连接字符串错误或您需要启动所需的任何服务或检查防火墙设置等。 &#34;连接被拒绝&#34;很明显,您要连接的服务存在某种配置问题。