my dog learned polymorphism*
The moose likes Java in General and the fly likes Embedded database in Java app? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Embedded database in Java app?" Watch "Embedded database in Java app?" New topic
Author

Embedded database in Java app?

Lido Scaggsinsky
Greenhorn

Joined: Sep 16, 2007
Posts: 9
I'm planning on putting together a (hopefully) simple client/server app which allows users to run a client and access the server app which hosts a database. I was going to use MySQL to handle the data, but I was wondering if there is a way I could bundle a simple database into the server app. That way I could distribute the client and server apps to anyone who has Java on their machine and they could hopefully use the program without having to set up and align a database program themselves. Thanks.


Lido
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Take a look at http://hsqldb.org/


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19685
    
  20

SQLite is another option, also used in PHP5. It can use a file, or memory if you omit the file in the connection string.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Masoud Kalali
Author
Ranch Hand

Joined: Jul 08, 2004
Posts: 531

Hi,
You may also look at http://www.h2database.com/ it is faster and more feature rich with a nice web based administration console in a very small footprint.

thanks.


Masoud Kalali
Software Engineer - My Weblog - GlassFish Security
Lido Scaggsinsky
Greenhorn

Joined: Sep 16, 2007
Posts: 9
Thanks. All of those look great. I didn't see any info on any of their sites that indicate that the db can be bundled with an application (in a jar file) and deployed with the application so the end user just double clicks the application file and it all works. Is there a term for that kind of thing?
Gaurav Arora
Ranch Hand

Joined: Aug 13, 2007
Posts: 35
If you plan to build your application on JDK1.6 then you might also want to look at http://db.apache.org/derby/ and http://developers.sun.com/javadb/ since they come bundled with the JDK (and I think the JRE).
Lido Scaggsinsky
Greenhorn

Joined: Sep 16, 2007
Posts: 9
Thanks. I'd use 1.6, but most of the people who I'm writing this for use Mac and probably won't be upgrading to Leopard any time soon. I heard something on Java Posse about an open jdk 1.6 that someone is working on so I might give that a try.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41635
    
  55
H2 is a commercial product, so you wouldn't be able to ship that with your app unless you negotiated a license.

SQLite is written in C, so shipping that would present some problems.

HSQLDB and Derby are your best options.


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19685
    
  20

Originally posted by Ulf Dittmer:
SQLite is written in C, so shipping that would present some problems.

Actually, no.

You don't need the SQLite program itself, all you need is the JDBC driver. This has been released under the BSD license, so you can ship it without any problems.

Check here for the JDBC driver. There is a pure Java driver available.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by Lido Scaggsinsky:
Thanks. I'd use 1.6, but most of the people who I'm writing this for use Mac and probably won't be upgrading to Leopard any time soon. I heard something on Java Posse about an open jdk 1.6 that someone is working on so I might give that a try.


You do not need Java 6 in order to use Derby (a.k. JavaDB).

Derby only comes bundled with Java 6, but you can run it with Java 5 for sure. I know, as I am happily doing so. And, yes, I am using Mac OS X.

To use Derby in Java 5, the easiest thing to do is to go to a Windows box somewhere, find or install Java 6 and copy the bundled Derby from it. That's what I did. It is a pure Java database, so the version you find on Windows will work on Mac.

I think Derby will work with even older Java than Java 5, but I have not tried that.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41635
    
  55
Originally posted by Peter Chase:
To use Derby in Java 5, the easiest thing to do is to go to a Windows box somewhere, find or install Java 6 and copy the bundled Derby from it.

I think Derby will work with even older Java than Java 5, but I have not tried that.

It may be even easier to just download it from http://db.apache.org/derby/

According to http://db.apache.org/derby/docs/dev/getstart/ Java 1.4 is sufficient to run it.
Lido Scaggsinsky
Greenhorn

Joined: Sep 16, 2007
Posts: 9
Thanks everyone. That helps a lot.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Embedded database in Java app?