You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by David Leader <d....@bio.gla.ac.uk> on 2007/10/25 22:03:29 UTC

Including a derby database in a Windows executable (was Can the derby.log file be suppressed?)

Changing the topic I wrote:

> Now, does anyone know how to include a derby database in a  
> Windows .exe file?
>

and John Embretsen replied

> If your database is read-only, I guess you could put your database  
> in a jar (your application jar file) and the wrap the jar in an exe  
> file
> You can read about putting the DB in a jar in the Derby Developer's  
> Guide, within the section "Creating Derby databases for read-only  
> use".

Thanks John.

I tried that last summer when we were first playing with derby, and I  
gave up as I was unable to find a path to the database. I've just  
tried again, with similar results. So, either it's not possible or  
I'm doing it wrong. Let me describe my setup.

1. DB external to the jar file  (Database name: DihedralizerDB)  
String url = "jdbc:derby: DihedralizerDB"
connection code for Connection conn:

				Class.forName("org.apache.derby.jdbc.EmbeddedDriver");	
				conn = DriverManager.getConnection(url);
OK. Now for the tough stuff:

2. DihedralizerDB as a directory within the jar file at the same  
level as the main method. (I've inspected the jar file with one of  
the available gui tools, so I know the structure is as I say it is.)  
I reference other directories containing image files and text files  
within the jar file ok, so I know how to include these and normally  
specify directory/filename. But clearly that will not work here. How  
do I reference the database? The Derby Developer's Guide instructions  
for referencing a database within a jar file has:

	jdbc:derby:jar:(pathToArchive)databasePathWithinArchive

but what is the path to the archive if it's in the same jar file as  
the main class?
  '.' ?   './' ?
Neither of these work for me with the path to the db specified as  
just the name of the db. The examples are not very helpful as they  
give absolute paths from someone's C drive, so presumably are for an  
external zipped or archived file (which I did manage to get to work  
just as a check).

jdbc:derby:jar:(C:/dbs.jar)products/boiledfood
jdbc:derby:jar:(C:/dbs.jar)sales

i.e. I have no joy with  jdbc:derby:jar:(./)DihedralizerDB or   
jdbc:derby:jar:(/)DihedralizerDB or most other variants I can think of.

Can it be done?

David








Re: Including a derby database in a Windows executable (was Can the derby.log file be suppressed?)

Posted by Stanley Bradbury <St...@gmail.com>.
David Leader wrote:
> Changing the topic I wrote:
>
>> Now, does anyone know how to include a derby database in a Windows 
>> .exe file?
>>
>
> and John Embretsen replied
>
>> If your database is read-only, I guess you could put your database in 
>> a jar (your application jar file) and the wrap the jar in an exe file
>> You can read about putting the DB in a jar in the Derby Developer's 
>> Guide, within the section "Creating Derby databases for read-only use".
>
> Thanks John.
>
> I tried that last summer when we were first playing with derby, and I 
> gave up as I was unable to find a path to the database. I've just 
> tried again, with similar results. So, either it's not possible or I'm 
> doing it wrong. Let me describe my setup.
>
> 1. DB external to the jar file  (Database name: DihedralizerDB) String 
> url = "jdbc:derby: DihedralizerDB"
> connection code for Connection conn:
>
>                 Class.forName("org.apache.derby.jdbc.EmbeddedDriver");   
>                 conn = DriverManager.getConnection(url);
> OK. Now for the tough stuff:
>
> 2. DihedralizerDB as a directory within the jar file at the same level 
> as the main method. (I've inspected the jar file with one of the 
> available gui tools, so I know the structure is as I say it is.) I 
> reference other directories containing image files and text files 
> within the jar file ok, so I know how to include these and normally 
> specify directory/filename. But clearly that will not work here. How 
> do I reference the database? The Derby Developer's Guide instructions 
> for referencing a database within a jar file has:
>
>     jdbc:derby:jar:(pathToArchive)databasePathWithinArchive
>
> but what is the path to the archive if it's in the same jar file as 
> the main class?
>  '.' ?   './' ?
> Neither of these work for me with the path to the db specified as just 
> the name of the db. The examples are not very helpful as they give 
> absolute paths from someone's C drive, so presumably are for an 
> external zipped or archived file (which I did manage to get to work 
> just as a check).
>
> jdbc:derby:jar:(C:/dbs.jar)products/boiledfood
> jdbc:derby:jar:(C:/dbs.jar)sales
>
> i.e. I have no joy with  jdbc:derby:jar:(./)DihedralizerDB or  
> jdbc:derby:jar:(/)DihedralizerDB or most other variants I can think of.
>
> Can it be done?
>
> David
>
Hi David -
I'm not certain but it seems you may be confusing the 
'path-to-the-archive' with the 'path-within-the archive'.  The 
path-to-the-archive needs to a filesystem path ending with the jarfile 
name.  So maybe something like:
jdbc:derby:jar:(/usr/me/myApp.jar)DihedralizerDB  ??

the 10.3 documents have improved examples that show examples of the JAR 
command creating the archive and the corresponding connection URL to use 
for each in the section "Accessing a read-only database in a zip/jar 
file.".  It also has this note that I did not notice in earlier manuals:

If you have trouble finding a database within an archive, check the 
contents of the archive
using your archive tool. The databasePathWithinArchive must match the 
one in the
archive. You might find that the path in the archive has a leading slash,

Example JAR command:
cd C:\london
jar cMf C:\dbs.jar sales

You can add multiple databases with jar. For example, this command puts 
the sales
databases and the boiledfood database (in the subdirectory products) 
into the archive.
cd C:\london
jar cMf C:\dbs.jar sales products\boiledfood

Example URLS:
jdbc:derby:jar:(C:/dbs.jar)products/boiledfood
jdbc:derby:jar:(C:/dbs.jar)sales