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.
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....
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.
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.
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.
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?
Related
I have never used Derby but I've seen that it can be embeded in my java application. If I decide to make my application by derby is there a way to place my database files in my specified application directory so I expect it to be portable and when I copy the database files to another application which can use them they will be copied safely?(I think that it was impossible for mysql thus it has a global configuration)
By the way I'd like to know if Derby has a client/server access system or it can be used like SQLite. My database is so easy and I need no client/server structure. Do client/server structures reduce the performance when they are compared with SQLite structure?
Derby is an open source relational database implemented entirely in Java based on Java, Sql, JDBC standards.
when I copy the database files to another application which can use
them they will be copied safely?
Yes it is portable and can be copied safely
I'd like to know if Derby has a client/server access system or it can
be used like SQLite
Derby supports the more familiar client/server mode with the Derby Network Client JDBC driver and Derby Network Server. check this link
for a full tutorial on how to use Derby with eclipse I'd suggest you to read this tutorial written by IBM
Good Luck
I need to create a simple Java application that connects to a local database file, and will run on a mac.
I've figured that JDBC is a good option, but what file format/drivers should I use?
Is .MDB files a possibility?
Thanks for any help!
For a small DB I would suggest using a DB written in Java. The DB's below or all
< 2mb. Keeping it in java means it is easy to transfer to Windows / Linux if need be.
Possible DB's include:
H2 - H2 has a mixed mode where the first time the DB is opened it is op
Advantages:
Mixed Mode
Only a couple of Files
has built-in SQL
HSQLDB - Version HSQLDB 1.80 is the smallest jar of the three (by a big margin)
The 2.* jars are similar in size to H2
Advantages:
Small size (Version 1.80)
Only a couple of Files
Apache Derby
All three offer Server and Embedded mode, H2 has mixed mode as well. All three are open source.
Use Apache Derby embedded in your application. This keeps it simple while still using standard JDBC.
H
Is .MDB files a possibility?
It could be, via a library like UCanAccess. However, using an Access database (.mdb or .accdb) would only be advisable if there was some other compelling reason to do so, e.g., to take a copy of the database file and use it with some other application that requires an Access database.
Otherwise, one of the suggestions from the other answers would probably be a better choice.
I'm creating a simple CMS software which doesn't have much data to be stored. I'm currently using mysql as my data provider and have a java application in the presentation layer. This CMS will be a standalone which means datacollection and processing will be done in a single computer.
I created a installer to install in my clients computers. But I need to setup mysql then the database as well. And my clients doesn't have sufficient IT knowledge to setup the databases themselves. So for each client I have to attend and install mysql server.
What I need is a way to integrate data-provider to the application without using mysql or any other sql or nosql server. So my clients can install it themselves using simple guided steps in installation wizards.
You can use one of embedded db, like JavaDB (ex. Derby). Support of this database is added to JRE. So all your client need is installed JRE. And you get full relational database without any installation and other stuff setup.
You can try using hsqldb or sqlite db. These dbs can be bundled with the application in memory or can use a simple file as db. Hope it helps
I found a good example here
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javadb/
thanks every one for help
Suppose I created a standalone application in java and distributed it through my website.
What I need to know is what is the ideal Database solution I can use so that all the users can use the application without installing anything extra.
For example, if I use SQL server or MySql database, the downloader will need those installed so that I can dump my database on it. Another solution I see is to use Database file like Microsoft Access .mdb file. But that too will need Microsoft Office installed on the client. XML files are platform independent but anyone can open and change them.
What is the solution used by most of the applications?
H2 is a very potent candidate for your need. We use it as a default RDBMS in all our demo applications and also for db-driven unit testing.
You could use an embedded database. There are hundreds for Java some which use SQL and many which don't. Any database you use, you may want the users to be able to maintain, so users editing the data may be a good thing.
You could consider Derby as it ships with Java.
I would use plain flat files which are CSV formatted unless you have a more specific requirement. e.g. you can load and edit them in excel/spreadsheet editor/text editor.
H2 is the successor of HSQLDB (same developer). It is not only one of the finest embedded DBs for JAVA, it is also free, even for commercial use. It's great with hibernate and comes with with a powerful web-interface (you can start it by running the h2 jar file). Additionally there is the possibility to encrypt you database (AES). We use that feature for getting some security aspects right with some of our projects.
check javadb. it is easy and can be redistributed
Firebird can do this : there is an embedded version.
There is some good java drivers
Using MDB files on Windows doesn't require any additional installation requirements such as Microsoft Office. DAO and ADO have come with the Windows OS since Windows 2000.
I want to write a small (5-6 table) desktop app in Java. I want to use Firebird 2.1. database. But I googled and see HSQLDB. I want to make a decision between Firebird and hsqldb.
So which database I have to use?
Firebird runs in a process of its own and your java app needs to communicate with it. The advantage HSQLDB has that it is written in java, and can run in the same process, which simplifies your installation and runtime check ups (Is the db running, connection errors, etc.). It can persist the data to the disk as well. AN additional option is the H2 database db, which also can run in process.
I'd go with the HSQLDB or H2.
For a desktop application an embedded database should be enough. hsqldb or h2 are very well suited for this. You just have to add the JAR file to you applications classpath. Firebird looks more complex.
Actually, H2 is more advanced than hsqldb.
Firebird is very good embedded database and just win an award at SouceForge this year
SQLite have good press for embedded Database too.
I recomend HSQLDB because it's implemented in Java (so you have the same platform as the application) and I guess that you don't need any of the feature for the project of that size that could FireBird provide.
Don't forget that Java 6 comes with JavaDB, and that may be a useful implementation for a first solution. It's a repackaged Apache Derby, and consequently quite powerful.