简体   繁体   中英

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:

the method format(String, Object[]) in the type String is not applicable for the arguments (String, String)

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.

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. You should make sure that you have the correct Java version set on your project.

How to change your Java version

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

IntelliJ

Menu -> File -> Project structure -> project SDK

Netbeans

This assumes that you installed JDK 1.6 and NetBeans knows about this.

  • Right-click on the Project and select Properties.
  • Under Library, select Java Platform JDK 1.8.
  • Select Source/Binary Format JDK8 in the Source category.

The JDK 1.8 must already have been supplied to NetBeans. To do that you got to menu -> Tools-> Java Platform Manager.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM