Erick M
Erick M

Reputation: 475

Deploying a Java App with database mysql desktop

I have written a Java desktop application which uses mysql as the database. For now am at crossroads on how to deploy this app with the mysql database. Is it possible to add the database into the app's jar file such that it will be automatically started whenever the user opens the app?

Upvotes: 1

Views: 2133

Answers (3)

Zoka
Zoka

Reputation: 445

NO, you can't include MySQL database in your JAR file. MySQL is not standalone database, you have to install it separately, so you can't include it in your JAR file. If you want standalone SQL database, you can use SQLite, though it will not be included in your JAR file, but you can make option inside your program to automatically create SQLite database file on a file system, and all necessary tables in it. SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed database engine in the world.

OR if you REALLY NEED to use MySQL database, you can use some distant server and have your MySQL installed there, so every user can access it if they have internet connection OR install MySQL separately on clients computer and configure database manually or automatically using sql dump file that has structure of a tables or through your Java program.

Upvotes: 3

DOCKMAN
DOCKMAN

Reputation: 11

create a different class which allows for the connection to the database. this class should have a UI which allows the user to add the credential for connection to the database then save to a file i.e. ./lib/file.txt. whenever you want the connection then this class is called. give it a try then i will send you a sample code after seeing your effort.

Upvotes: 1

Amir Afghani
Amir Afghani

Reputation: 38531

MySql is not a platform agnostic executable. Therefore, if you were to package your application with MySQL (forget about the fact that you need to install MySQL!), it wouldn't be binary compatible on all computers (think mac, pc, linux)

You could use something like H2 or Derby, which are just SQL like databases written in Java. Then you can just ship your jar file and include the database program with it.

Upvotes: 3

Related Questions