When you specify the same directory, a new directory will not be created. In actual fact both dataset
and datsetnew
point to the same physical RDF store. I.e. if you try to create an transaction on both of them you will get a Currently in an active transaction org.apache.jena.dboe.transaction.txn.TransactionException
. So NO, you cannot create multiple datasets in a single TDB directory.
Another observation is that you seem to be using TDB1 rather than TDB2. TDB2 is the later version and it would therefore be the best to use. Then your code will look as follows:
Path path = Paths.get(".").toAbsolutePath().normalize();
String dbDir = path.toFile().getAbsolutePath() + "/db/";
Location location = Location.create(dbDir);
Dataset dataset = TDB2Factory.connectDataset(location);
String strQuery = "INSERT DATA {<http://dbpedia.org/resource/Grace_Hopper> <http://xmlns.com/foaf/0.1/surname> \"Hopper\" .}";
dataset.begin(ReadWrite.WRITE);
UpdateRequest updateRequest = UpdateFactory.create(strQuery);
UpdateProcessor updateProcessor = UpdateExecutionFactory.create(updateRequest, dataset);
updateProcessor.execute();
dataset.commit();
dataset.close();