2

I created a java project that uses a database to retrieve, edit, and save data. I finished the project using Netbeans and now I want to create an installation out of the project. To do so, I want to include the database to be installed along with the project. The code I am using to connect to the database is:

Class.forName("org.h2.Driver"); 
Connection con = DriverManager.getConnection("jdbc:h2:~/localhost/gallerie", "root", "123");

The application is working fine on my pc, but I need it to be installed as an executable on other pcs.

What is the best way to do so?

Brute Force
  • 464
  • 4
  • 15

1 Answers1

2

One way to do this is with the setup packager from stardust software. You will also need to include some script or some Java code to create the database and the database user. You don't need to do that with the installer. Instead, create some file or store something using the Preferences API so the program knows when it is running for the first time. When your program runs for the first time it needs to call some function to create the database user and the database.

Alternatively, you could also package the database files with your application as described by this stack overflow question.

Community
  • 1
  • 1
Thorn
  • 4,015
  • 4
  • 23
  • 42
  • If I use the setup packager, do I need to include anything to create the database? I have my database on my pc (C:\Users\MY User\localhost\galllerie.h2.db). – Brute Force Jun 29 '13 at 16:57
  • 1
    The database should be a file that you have on your local hard drive that you can include in the package. Or you can include some code to create the database programmatically. – Thorn Jun 29 '13 at 19:07