db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rhys Campbell" <rhys.campb...@da-systems.co.uk>
Subject RE: Storing/Accessing a Derby database inside a JAR
Date Thu, 06 Apr 2006 10:24:14 GMT

Hi,

I've use getResource() to access images and text files contained within
jar files. Maybe this will work for Derby databases?

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getRe
source(java.lang.String) 

-----Original Message-----
From: Susan Cline [mailto:home4slc@pacbell.net] 
Sent: 03 April 2006 18:44
To: Derby Discussion
Subject: Re: Storing/Accessing a Derby database inside a JAR

Hi Daniel,

I have not tried this myself, but looking at the documentation 
and looking at the error I wonder if the the path to the database 
from within the jar file is correct.

Please see my specific comments below.

Susan

--- Daniel Morton <djmorton42@yahoo.com> wrote:

[ snip ]
> 
> I created a jar using:
> 
> jar cf NameGenerator.jar djm NameDB
> 
> so that the database, and the NameGenerator class in
> the djm package is put in to the jar.  However, if I
> run a test.java program to create a NameGenerator
> object, it errors when trying to connect to the
> database:  SQLException: Database '/NameDB' not found.
> 
> My connection string (per the Derby Documentation) is:
> DriverManager.getConnection("jdbc:derby:/NameDB");
> I've tried multiple varitions on this (ie. NameDB,
> /NameDB, /NameDB/ etc.)
> 
> And in the above, the NameGenerator.jar is in the
> classpath.

I believe trying to access the database this way will not work
as per the documentation, you need to use the jdbc:derby:jar
syntax as you have below.

> 
> I've also tried specicifying the explicit path (ala
> the Derby Manual):
>
DriverManager.getConnection("jdbc:derby:jar:(C:/project/NameList/NameGen
erator.jar)/NameDB");
> 
> Which results in the SQLException: Failed to start
> database
> 'jar:(C:/project/NameList/NameGenerator.jar)/NameDB'
> Java Exception: The system cannot find the file
> specified: java.util.zip.ZipException.

This error looks more hopeful :-)  At least it is looking
for the /NameDB in the jar file.  But I'm thinking that
the path to the NameDB relative to the jar file is the
problem.  When you "unjar" the NameGenerator.jar file
what is the path to NameDB?  What happens if you try
this URL instead;

'jar:(C:/project/NameList/NameGenerator.jar)NameDB'
> 
[ snip ]
> Also, once I get this
> sorted out, is there a way to include derby.jar inside
> NameGenerator.jar so that just the one file could be
> distributed?
> 
I don't know the answer to this, but it seems like it might
be tough since it would be a chicken-and-egg situation.  In 
order to use the Derby JDBC connection URL it would need to
have derby.jar in the classpath first.  Hopefully someone else
can help you with this one.



Mime
View raw message