connecting to a file-based derby database

Amir.F picture Amir.F · May 19, 2012 · Viewed 14.7k times · Source

I want to work with a file-based database using apache derby. I was wondering if anyone can carify how to connect & create this database using netbeans as an IDE. I passed through derby manuals trying to figure this one out, but all i got was "Embedded Derby JDBC Database Connection", which i was told is not a file-based approach, and either way, the connection didn't seem to work. any help would be much appreciated

Answer

Bill picture Bill · May 19, 2012

To create one, your jdbc url will be: jdbc:derby:foo;create=true, and it will create a database called foo in the derby system directory. If you want to create one in an absolute location on your hard drive, specify an absolute path. jdbc:derby:/home/me/foo;create=true.

Once the database is created, you can connect to it with the same url, or you can drop the ;create=true part off.

You can set the derby system directory via system properties, e.g. System.setProperty("derby.system.homeSystem.setProp", "/home/bar/whatever");. I think you would need to do this before starting a derby database has been started, but I've never tried to do it afterwards. I have found that setting the derby system home for the app and specifying relative database url to work better, but that's a personal preference.