Question

I am creating a new database in stardog using java.

When I am creating the database and importing a RDF file in localhost its working.

But when I am creating db in remote server I am getting a file not found exception for the same RDF file.

Please take a look at my code

    System.out.println("start updating db");
    String myDBName = "myDB" ;

    StardogDBMS dbms =
            //StardogDBMS.toServer("snarl://localhost:5820/")
            StardogDBMS.toServer("snarl://myRemoteServer:5820/")
            .credentials("admin", "admin".toCharArray()).login();

    File file = new File("src\\main\\webapp\\test.rdf"))

    System.out.println("creating " + myDBName +" and loading the rdf file" );

    dbms.disk(myDBName).create(file));
    dbms.logout();
    System.out.println("created " + myDBName +" and loaded the rdf file" );

please help. Is there any turnaround like passing a stream to database for importing RDF file. Here is the exception I am getting.

start updating db
creating myDB and loading the rdf file      
File: xxx\xxxx\test.RDF Message: java.io.FileNotFoundException: xxx\xxxx\test.RDF (No such file or directory)
created myDB and loaded the rdf file
Était-ce utile?

La solution 3

I guess what Michael answered is the reason for the exception. I found a go around method for this issue.

Instead of creating database and bulk loading the RDF/OWL files. Create a connection to the stardog DB. and import the RDF files through the connection.

sample code is given below

System.out.println("start updating db");
String myDBName = "myDB" ;

StardogDBMS dbms =
        //StardogDBMS.toServer("snarl://localhost:5820/")
        StardogDBMS.toServer("snarl://myRemoteServer:5820/")
        .credentials("admin", "admin".toCharArray()).login();

File file = new File("src\\main\\webapp\\test.rdf"))

System.out.println("creating " + myDBName);

dbms.disk(myDBName).create());
dbms.logout();

aConn = ConnectionConfiguration.to(myDBName) // the name of the db to connect to
            .credentials("admin", "admin") // the credentials with which to connect
            .url("snarl://myRemoteServer:5820/")
            .connect(); // now open the connection

    System.out.println("importing files to "+myDBName);
    aConn.begin();
    aConn.add().io().format(RDFFormat.RDFXML).stream(file);     
    aConn.commit();
    System.out.println("files imported to "+myDBName);

    System.out.println("DB Updated");

Autres conseils

The error message indicates that the bulk loader for the disk database cannot find the specified file. Files are not transferred from the client to the server for bulk loading when using the SNARL protocol, which is probably the source of the error.

If both server & client are running on the same machine, it's likely that your relative path is incorrect when the server is reading it, that path would be relative to STARDOG_HOME, and likely incorrect in that case. So if they're both on the same machine, use an absolute path and it should work. If they're on separate machines, bulk load from the CLI on the machine with the server.

If you want to use HTTP, the files will be transferred, but you will get poor bulk load performance because of the network overhead of sending the file to the server. Again, you are best served doing bulk loads on the machine with the server.

Without knowing what dbms.disk(myDBName).create(file)); is doing it's hard to say, but are you sure it's not attempting to read a file src\\main\\webapp\\test.rdf which exists locally but not on the remote server?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top