[英]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版本。
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知道这一点。
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.