Embedding mysql in java desktop application
Asked Answered
P

5

11

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.

Poncho answered 3/8, 2010 at 3:25 Comment(2)
you embed mysql in desktop app? how? is it possible?Coastland
It seems very useful for me alsoSilversmith
L
7

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....

Liege answered 3/8, 2010 at 3:34 Comment(2)
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.Adamis
@Cesar: Thx, I didn't know about libmysqldLiege
D
3

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.

Delinquency answered 3/8, 2010 at 3:50 Comment(2)
can h2 manage large amount of data and can we make a back up of it easily?Poncho
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.Delinquency
D
1

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.

Docilla answered 3/8, 2010 at 3:34 Comment(1)
considering it is possible , as you said , can you mention any tutorial link how to configure it , let it be complex or soAssumption
R
1

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.

Ritzy answered 3/8, 2010 at 7:51 Comment(0)
W
0

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?

Worser answered 3/8, 2010 at 6:40 Comment(4)
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?Poncho
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.Colcannon
The rows can be 5k and then they shall be moved to archive...now can u help?Poncho
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.Colcannon

© 2022 - 2024 — McMap. All rights reserved.