简体   繁体   中英

Distribute a database made with JavaDB with Java program

I'm creating a program in Java in which I have to use a lot of tables. I made the decision to create all those tables in a JavaDB file.

However, now I want to distribute this filled JavaDB file with my JAR file for distribution, since connecting to a server is not an option.

In the past I could only distribute an empty database with the JAR by using that Derby package.

Any ideas?

Thank you so much!

I'm not sure I understood the question but it is possible to package a read-only database inside a JAR. From the derby documentation:

Accessing Databases-in-a-Jar in the Class Path

Once an archive containing one or more Derby databases has been created it can be placed in the class path. This allows access to a database from within an application without the application's knowing the path of the archive. When jar or zip files are part of the class path, you do not have to specify the jar subsubprotocol to connect to them.

To access a database in a zip or jar file in the class path:

  1. Set the class path to include the jar or zip file before starting up Derby:

     CLASSPATH="C:\\dbs.jar;%CLASSPATH%" 
  2. Connect to a database within the jar or zip file with one of the following connection URLs:

     jdbc:derby:/databasePathWithinArchive (standard syntax) jdbc:derby:classpath:/databasePathWithinArchive (syntax with subsubprotocol) 

For example:

 jdbc:derby:/products/boiledfood jdbc:derby:classpath:/products/boiledfood 

If this doesn't answer the question, please clarify.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM