简体   繁体   English

如何在Eclipse中使用Java与Fuseki进行交互

[英]How to interact with Fuseki using Java in Eclipse

I'm following this tutorial here to insert a new resource into Fuseki 's dataset, but I'm getting this error: 我在这里按照本教程将新资源插入Fuseki的数据集中,但出现此错误:

the method format(String, Object[]) in the type String is not applicable for the arguments (String, String) 字符串类型中的方法format(String,Object [])不适用于参数(字符串,字符串)

This is the code: 这是代码:

import java.util.UUID;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.update.UpdateExecutionFactory;
import com.hp.hpl.jena.update.UpdateFactory;
import com.hp.hpl.jena.update.UpdateProcessor;

/**
 * Example connection to Fuseki. For this to work, you need to start a local
 * Fuseki server like this: ./fuseki-server --update --mem /ds
 */
public class FusekiTest {
    /** A template for creating a nice SPARUL query */
    private static final String UPDATE_TEMPLATE = 
            "PREFIX dc: <http://purl.org/dc/elements/1.1/>"
            + "INSERT DATA"
            + "{ <http://example/%s>    dc:title    \"A new book\" ;"
            + "                         dc:creator  \"A.N.Other\" ." + "}   ";

    public static void main(String[] args) {
        //Add a new book to the collection
        String id = UUID.randomUUID().toString();
        System.out.println(String.format("Adding %s", id));
        UpdateProcessor upp = UpdateExecutionFactory.createRemote(
                UpdateFactory.create(String.format(UPDATE_TEMPLATE, id)), 
                "http://localhost:3030/ds/update");
        upp.execute();
    }

}

在此处输入图片说明

How can I fix that error? 我该如何解决该错误?

This issue is common when the java project version is 1.4. 当Java项目版本为1.4时,此问题很常见。

It's a common problem that the project Java version is set to 1.4 or 1.6 by default in the template by the IDE. 一个常见的问题是,IDE将模板中的项目Java版本默认设置为1.4或1.6。 You should make sure that you have the correct Java version set on your project. 您应该确保在项目上设置了正确的Java版本。

How to change your Java version 如何更改您的Java版本

Eclipse: 日食:

Right click project -> Properties -> Java Build Path -> select JRE System Library click Edit and select JDK or JRE after then click Java Compiler and select Compiler compliance level to 1.8 右键单击项目->属性-> Java构建路径->选择JRE系统库,单击编辑,然后选择JDK或JRE,然后单击Java编译器,然后选择编译器遵从性级别为1.8

IntelliJ IntelliJ

Menu -> File -> Project structure -> project SDK 菜单->文件->项目结构->项目SDK

Netbeans 网豆

This assumes that you installed JDK 1.6 and NetBeans knows about this. 假定您已安装JDK 1.6,并且NetBeans知道这一点。

  • Right-click on the Project and select Properties. 右键单击项目,然后选择属性。
  • Under Library, select Java Platform JDK 1.8. 在“库”下,选择“ Java Platform JDK 1.8”。
  • Select Source/Binary Format JDK8 in the Source category. 在“源”类别中选择“源/二进制格式JDK8”。

The JDK 1.8 must already have been supplied to NetBeans. JDK 1.8必须已经提供给NetBeans。 To do that you got to menu -> Tools-> Java Platform Manager. 为此,您需要进入菜单->工具-> Java平台管理器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Java将RDF代码上传到fuseki服务器? - How to upload RDF code to fuseki server using Java? 如何使用Java与.aspx进行交互? - How to interact with a .aspx using Java? 如何使用 Java 代码启动 Fuseki 服务器并使用 java 代码将 OWL 文件上传到它? - How to start Fuseki server using Java code and upload OWL file to it using java code? 如何使用java实现expect“interact”命令 - how to implement expect “interact” command using java 如何使用Java与已经运行的进程进行交互 - How to interact with already running process using java 如何使用 Apache Jena Java API 创建 Fuseki SPARQL 服务器? - How do you create a Fuseki SPARQL server using the Apache Jena Java API? 与在Eclipse中使用常规Java代码相比,使用Google Apps脚本与Google表格进行交互有什么优势? - What are advantages of using Google Apps Script to interact with Google Sheets over using regular Java code in Eclipse? 如何使用JSON在JSP和Java控制器之间进行交互? - How to interact between JSP and Java controller using JSON? 我将如何使用Java与Selenium Webdriver中的此输入框进行交互? - How would I interact with this input box in Selenium Webdriver using Java? 如何使用Java与MySQL交互? - How do I use interact with MySQL using Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM