Sajad
Sajad

Reputation: 2363

Create Jar file with IntelliJ IDEA that has mysql database

I want to create (export) my application into a Jar file to be portable.

How can i put my database contents with jar file?

For e.g for pictures, i put pictures folder beside my jar file, and it shows pictures correctly.

UPDATE

A peace of code to connect to database:

connection = DriverManager.getConnection("jdbc:mysql://localhost/Library", "root", "1234");

Upvotes: 1

Views: 1710

Answers (2)

Emil Lundberg
Emil Lundberg

Reputation: 7379

If you want to distribute a copy of your database with each copy of your application, I think using MySQL will be a bit complicated. You may want to look into using a database system designed to be embedded, such as SQLite, instead. A complete SQLite database is a single text file - you'd simply distribute your one mydatabase.db file along with the jar. See the examples at the above link.

Upvotes: 1

Amit Sharma
Amit Sharma

Reputation: 6154

There are two approaches you could use:

Approach 1
Do you really need to use database? If not, store your data on files in file system, that way you can easily export it with data.

Approach 2
Bundle the mysql installation directory in your jar / installer. Write a scripts which starts up both MySQL server and you application.

Upvotes: 1

Related Questions