views:

81

answers:

5

hi i am not clear about steps/configuration details about how i can embed mysql in a Java desktop application so that it(application) can be installed on any machine through a single executable file and doing so sets up database and also provides an exe to run the app.Till now i have built my app using netbeans and i have used mysql to set up database.plz guide me further.

+1  A: 

MySQL isn't an embedded database - the only JAR related to it is the JDBC driver. It requires a installation process, which might be able to be scripted via Java, but the process will definitely function outside of the Java application you intend it to support. Meaning, you can turn off your Java application but the MySQL service/daemon will still be running.

Only the libmysqld is embeddable.

There are embedded databases - SQLite, Firebird - and embedded databases made in Java - HSQL, Derby/(can't remember what it was called before). I believe SQL Server Compact Edition is embeddable, while SQL Server Express/MSDE is not. I don't know if Oracle has an embeddable version....

OMG Ponies
There is a version of MySQL, libmysqld for embedding. But I agree with you in that there are other databases more suited to the job. Since this is Java I would recommend HSQL.
Cesar
@Cesar: Thx, I didn't know about libmysqld
OMG Ponies
A: 

While theoritcaly possable it would not be easy. The standard MySql distributions assume you want to set up a general purpose database server with separate from the client applications cominicating via odbc etc.

You may be better looking at the "pure java" options like HSQL or JavaDB which are designed to be embedded in a java application, and need little or no "setup".

Another possibility is Sqlite which only needs a single binary plus the sqljbbc jar file. This is again designed from scratch to be embedded inside an application and requires zero admin apart from allocating a file for the database.

James Anderson
A: 

I would strongly recommend H2. It is a very fast embedded database written in Java and I've found it easier to use than some of the others mentioned such as HSQL.

Edit:

On the H2 website, you can see a speed comparison of H2 vs Derby, HSQL, MySql, etc...

Here's information on how to backup the database.

Jay Askren
can h2 manage large amount of data and can we make a back up of it easily?
Andrew
Backing up h2 is fairly easy. The last time I tried it, H2 did not scale well up to gigabytes of data like MySql can. I think it should be able to handle 5000 rows though without much trouble.
Jay Askren
A: 

If you want an embedded database with java, then use one written in Java designed to be embedded. I know Apache Derby Can be embedded and apparently H2 too.

How big amount of data dó you need the database to handle?

Thorbjørn Ravn Andersen
I am working on kind of accounting software that has to keep track of payments made and then generate reports accordingly..now what kind of embedded database can suffice my requirement?
Andrew
Come with estimates of the amount of data you expect. Just the size - 1, 1000, 1000000 etc. - for the number of tables, rows in each table, total amount of data for each table, etc.
Thorbjørn Ravn Andersen
The rows can be 5k and then they shall be moved to archive...now can u help?
Andrew
This amount of data should not be too much for an embedded database. Personally I would have a go with Apache Derby, and learning where the files for the database tables will be stored, so I could put them in the correct location.
Thorbjørn Ravn Andersen
A: 

Take a look at http://dev.mysql.com/doc/refman/5.0/en/connector-mxj.html. I do not remember the exact details but I was able to embed MySQL db in desktop application without user needing to install it separately.

The key class is com.mysql.management.MysqldResource.

Here is the example, http://dev.mysql.com/doc/refman/5.0/en/connector-mxj-configuration-java-object.html

The mysql-connector-mxj-gpl-db-files.jar file contains MySQL installation files for all the platforms. If you know which is your target platform, you can strip other platform versions from jar, to reduce download size for end user.

Adi