Database Url in classpath

1,339 views
Skip to first unread message

Costantino

unread,
Dec 7, 2008, 4:55:58 PM12/7/08
to H2 Database
Hallo,

first of all, H2 is very nice!
I have a question: there is a way, in the embedded mode, to locate a
database that is in the classpath?
For example my database name is MyDb and the database files are in the
package"org.resource", and my connection url looks like this:
jdbc:h2:classpath://org.resource.MyDb

At the moment I'm using this workaround: I look for the mydb.data.db
file in the classpath with Class.getResource(..) then I get the
absolute file path and substitute it at runtime in the connection url.

Thanks in advance,
Costantino

Thomas Mueller

unread,
Dec 10, 2008, 5:42:41 PM12/10/08
to h2-da...@googlegroups.com
Hi,

I will add a feature request for supporting the classpath directly.

Regards,
Thomas

On Wed, Dec 10, 2008 at 11:41 PM, Thomas Mueller
<thomas.to...@gmail.com> wrote:
> Hi,
>
> If you know the jar file name, you can use the zip file mechanism. See also:
>
> http://www.h2database.com/html/features.html#database_in_zip
>
> There is a way to find out the name of the jar file, but it's a bit
> tricky. I'm not sure if this works in your case: System.out.println(
> getClass().getResource(getClass().getName()+".class"));
>
> Regards,
> Thomas

Thomas Mueller

unread,
Dec 10, 2008, 5:41:00 PM12/10/08
to h2-da...@googlegroups.com
Hi,

If you know the jar file name, you can use the zip file mechanism. See also:

http://www.h2database.com/html/features.html#database_in_zip

There is a way to find out the name of the jar file, but it's a bit
tricky. I'm not sure if this works in your case: System.out.println(
getClass().getResource(getClass().getName()+".class"));

Regards,
Thomas

On Sun, Dec 7, 2008 at 10:55 PM, Costantino <c.c...@gmail.com> wrote:
>

Costantino

unread,
Dec 11, 2008, 6:59:14 AM12/11/08
to H2 Database
Thanks, but a zipped db is too slow for my needings.
The db files are actually in Classpath but they are uncompressed.

There is no way to make the performances of zipped db comparable to
that ones of uncompressed files?

On Dec 10, 11:41 pm, "Thomas Mueller" <thomas.tom.muel...@gmail.com>
wrote:
> Hi,
>
> If you know the jar file name, you can use the zip file mechanism. See also:
>
> http://www.h2database.com/html/features.html#database_in_zip
>
> There is a way to find out the name of the jar file, but it's a bit
> tricky. I'm not sure if this works in your case: System.out.println(
> getClass().getResource(getClass().getName()+".class"));
>
> Regards,
> Thomas
>

Thomas Mueller

unread,
Dec 12, 2008, 3:59:59 PM12/12/08
to h2-da...@googlegroups.com
Hi,

> Thanks, but a zipped db is too slow for my needings.

Then db files in the classpath will not help.

The main problem for both zipped databases and databases in the
classpath is: you can't do real random access. You can only read from
a stream. Random access is required, so it is simulated like this:
When seek(pos) larger than current position, then a skip is made
(which is basically a read). If the seek pos is smaller, then the
stream is closed and re-opened. This is very slow.

> There is no way to make the performances of zipped db comparable to
> that ones of uncompressed files?

No. Not that I know of.

Regards,
Thomas

Reply all
Reply to author
Forward
0 new messages