0

I want to upload turle files on GraphDB using RDF4J framework. Any suggestion will be highly appreciated.

I tried the code below (note: I am not professional in Java). There is no error but I cannot see the data on GraphDB.

String repositoryUrl = "http://localhost:7200/repository/...";
        String username = "iiuu";
        String password = "iibb";
        String filePath = "/.../xxx.ttl";
        
      //Equivalent command conversion for Java execution
              String[] command = { "curl", "-u", username + ":" + password, "-X", "POST", "-F", "cmd=unlockPage", "-F","Content-Type: application/x-turtle",
                      "-T",
                      "path=" + filePath, "-F", "_charset_=utf-8", repositoryUrl };

 

              ProcessBuilder process = new ProcessBuilder(command);
              Process p;
              try {
                  p = process.start();
                  BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
                  StringBuilder builder = new StringBuilder();
                  String line = null;
                  while ((line = reader.readLine()) != null) {
                      builder.append(line);
                      builder.append(System.getProperty("line.separator"));
                  }
                  String result = builder.toString();
                  System.out.print(result);
                 

1 Answers1

1

You can take a look at the RDF4J getting started guide for additional examples - https://rdf4j.org/documentation/tutorials/getting-started/ - Example 14: load a file directly into a database

https://github.com/eclipse/rdf4j/blob/main/examples/src/main/java/org/eclipse/rdf4j/examples/repository/Example14AddRDFToDatabase.java

Konstantin Petrov
  • 1,058
  • 6
  • 11