Hello there,
I am attempting to create a database and add a resource to it
programatically in Java.
If I use this code:
public static void main(String[] args) {
try (ClientSession session = new ClientSession("localhost", 1984,
"admin", "admin")) {
session.execute("SET INTPARSE true");
session.execute("CREATE DB TESTING D:\\VP DB\\export.xml");
session.execute("CLOSE");
session.close();
} catch (IOException ex) {
Logger.getLogger(BaseXTesting.class.getName()).log(Level.SEVERE, null, ex);
}
The code run's without a problem.
When I attempt to do this:
public static void main(String[] args) {
// TODO code application logic here
CreateDB createDBCmd = new CreateDB("TESTING");
Open openCmd = new Open("TESTING");
Add addCmd = new Add("\\BaseXTarget", "D:\\VP DB\\export.xml");
Set setCmd = new Set("INTPARSE", true);
try (ClientSession session = new ClientSession("localhost", 1984,
"admin", "admin")) {
session.execute(setCmd);
session.execute(openCmd);
session.execute(addCmd);
session.close();
} catch (IOException ex) {
Logger.getLogger(BaseXTesting.class.getName()).log(Level.SEVERE, null, ex);
}
The following exception is thrown:
run:
Jan 26, 2017 5:03:17 PM basextesting.BaseXTesting main
SEVERE: null
org.basex.core.BaseXException: "BaseXTarget.xml" (Line 1): No text allowed
before root element.
at org.basex.api.client.ClientSession.receive(ClientSession.java:191)
at org.basex.api.client.ClientSession.execute(ClientSession.java:160)
at org.basex.api.client.ClientSession.execute(ClientSession.java:165)
at org.basex.api.client.Session.execute(Session.java:36)
at basextesting.BaseXTesting.main(BaseXTesting.java:36)
BUILD SUCCESSFUL (total time: 0 seconds)
It could be me being daft, but both pieces of code should achieve the same
thing as they point to the same file, but when classes are used instead of
command strings, the BaseXException is thrown.
I have checked my data for the byte order mark, and have the ensure it is
enoced using UTF-8.
Help!
Shaun