简体   繁体   中英

Distributing a Derby DB with a Java application

I have a table in a application, which loads in data from a Derby DB with a Client/Server driver. Everything works in NetBeans, even with the NetBeans DB service disconnected, but not when running the standalone distributive app. I have included the derbyclient.jar in the classpath. I have the startNetworkServer.bat in the distributable apps folder(not in /dist), and it is run within the program at initialization. I'm new to Derby, so maybe i'm missing/not including something important?


First i load the startNetworkServer.bat file:

ProcessBuilder pb = new ProcessBuilder("D:/Users/lapa2/Desktop/Skeneris/InventoryController/dist/startNetworkServer.bat");
p = pb.start();

Which doesn't work, I set that by manually opening cmd line for now.

Then the driver and connection are set:

private static final String jdbcDriver
= "org.apache.derby.jdbc.ClientDriver";


private static final String jdbcURL
    = "jdbc:derby://localhost:1527/D:/Users/lapa2/Desktop/Skeneris/InventoryController/dist/Lapa;create=true;";

Then I query everything i want:

db = new DataBase(userName,password,databaseName);
    String dbStatement = "select * from "+ schemaName + ".PRECES";
    ResultSet rs = db.executeQuery(dbStatement);

Doing like this, everything works in NetBeans, but no response when running the .JAR.

Try looking into a Derby Embedded Database. It is way more easier to pack with your program and as well as distribute plus you don't have to recreate the whole database. Whatever you make during the development stays with it.

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