Code for setting Derby's home
Details
According to John O'Conner (see sources), if you set the Environment Variable derby.system.home
to
a directory, Derby will look in that directory for any named database. It has to be said that I haven't had a
lot of luck with it, despite setting the Environment Variable fine. Anyhow, I thought you might like to
have a play with it - if nothing else it shows how to get the user's home directory.
Original author/s: John O'Conner
Original location/s: Using Java DB in Desktop Applications
Adapted by: Andy Evans
License: Berkeley license
More info:
Code
// Initiate the database driver. try { Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } // Get the user's home directory and set the Environment Variable. String userHomeDir = System.getProperty("user.home", "."); String systemDir = userHomeDir + "/.database"; System.setProperty("derby.system.home", systemDir); // Connect to a database called 'Results' Connection conn = null; String strUrl = "jdbc:derby:Results"; try { conn = DriverManager.getConnection(strUrl); } catch (SQLException sqle) { sqle.printStackTrace(); }