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 Brian Ehmann <be...@gmail.com> on 2006/08/29 14:59:22 UTC

unable to access DB on classpath

Hey everyone,

First, forgive me if this is a dumb question, but I can't seem to  
find the answer in the derby documentation.

I am developing a web app on tomcat that uses container managed  
security and I would like to migrate the authentication data from  
mysql to an embedded derby db.  I have created the DB, using ij, as  
follows:

driver 'org.apache.derby.jdbc.EmbeddedDriver';
connect 'jdbc:derby:AerosmithDB;create=true';
create table users (username varchar(15) not null primary key,  
password varchar(35) not null);
create table userroles ( username varchar(15) not null, role varchar 
(15) not null, primary key (username, role));
insert into users(username, password) values ('test', 'test');
insert into userroles(username, role) values ('test', 'registereduser');
commit;
disconnect;

I then jar the "AerosmithDB" directory into a jar and place it on the  
classpath.  Unfortunately, using ij, I am not able to connect to the  
database that is on the classpath.  See below:

$ echo $CLASSPATH
/Users/brian/src/eclipse/workspace/Aerosmith/WebContent/WEB-INF/ 
AerosmithDB.jar:/Developer/Java/db-derby-10.1.3.1/lib/derby.jar:/ 
Developer/Java/db-derby-10.1.3.1/lib/derbytools.jar
$ ij
ij version 10.1
ij> driver 'org.apache.derby.jdbc.EmbeddedDriver';
ij> connect 'jdbc:derby:/AerosmithDB';
ERROR XJ004: Database '/AerosmithDB' not found.
ij> connect 'jdbc:derby:AerosmithDB';
ERROR XJ004: Database 'AerosmithDB' not found.
ij> connect 'jdbc:derby:classpath:/AerosmithDB';
ERROR XJ004: Database 'classpath:/AerosmithDB' not found.
ij> connect 'jdbc:derby:classpath:AerosmithDB';

Any ideas?

Thanks,

Brian

Re: unable to access DB on classpath

Posted by Anders Morken <an...@stud.ntnu.no>.
Brian Ehmann:
> First, when jar-ing a db directory it was necessary to jar from one  
> level up and not the db directory itself.  For example, if the db,  
> named myDB, is in /data/myDB, it is necessary to jar the /data  
> directory.

Uhm, minor clarification: If you've created a database called myDB
placed in /data, run "jar cf /data/myDB.jar myDB/" in the /data
directory to create the database jar file. A jar file created by running
"jar cf /data/myDB.jar ." in /data/myDB won't be discovered by Derby.

I think the docs could use a bit of polishing here, and maybe a few
examples of how you'd go about creating and using jar files with
databases wouldn't hurt. =)

=)

-- 
Anders Morken

My opinions may have changed, but not the fact that I am right!

Re: unable to access DB on classpath

Posted by Brian Ehmann <be...@gmail.com>.
andersmo in the #derby irc room figured this out for me:

First, when jar-ing a db directory it was necessary to jar from one  
level up and not the db directory itself.  For example, if the db,  
named myDB, is in /data/myDB, it is necessary to jar the /data  
directory.
Next, set the jar containing the db on the classpath and connect to  
it using the following connection string:
'jdbc:derby:classpath:myDB'

Thanks again andersmo.

On Aug 29, 2006, at 8:59 AM, Brian Ehmann wrote:

> Hey everyone,
>
> First, forgive me if this is a dumb question, but I can't seem to  
> find the answer in the derby documentation.
>
> I am developing a web app on tomcat that uses container managed  
> security and I would like to migrate the authentication data from  
> mysql to an embedded derby db.  I have created the DB, using ij, as  
> follows:
>
> driver 'org.apache.derby.jdbc.EmbeddedDriver';
> connect 'jdbc:derby:AerosmithDB;create=true';
> create table users (username varchar(15) not null primary key,  
> password varchar(35) not null);
> create table userroles ( username varchar(15) not null, role varchar 
> (15) not null, primary key (username, role));
> insert into users(username, password) values ('test', 'test');
> insert into userroles(username, role) values ('test',  
> 'registereduser');
> commit;
> disconnect;
>
> I then jar the "AerosmithDB" directory into a jar and place it on  
> the classpath.  Unfortunately, using ij, I am not able to connect  
> to the database that is on the classpath.  See below:
>
> $ echo $CLASSPATH
> /Users/brian/src/eclipse/workspace/Aerosmith/WebContent/WEB-INF/ 
> AerosmithDB.jar:/Developer/Java/db-derby-10.1.3.1/lib/derby.jar:/ 
> Developer/Java/db-derby-10.1.3.1/lib/derbytools.jar
> $ ij
> ij version 10.1
> ij> driver 'org.apache.derby.jdbc.EmbeddedDriver';
> ij> connect 'jdbc:derby:/AerosmithDB';
> ERROR XJ004: Database '/AerosmithDB' not found.
> ij> connect 'jdbc:derby:AerosmithDB';
> ERROR XJ004: Database 'AerosmithDB' not found.
> ij> connect 'jdbc:derby:classpath:/AerosmithDB';
> ERROR XJ004: Database 'classpath:/AerosmithDB' not found.
> ij> connect 'jdbc:derby:classpath:AerosmithDB';
>
> Any ideas?
>
> Thanks,
>
> Brian