问题
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!
回答1:
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:
Set the class path to include the jar or zip file before starting up Derby:
CLASSPATH="C:\dbs.jar;%CLASSPATH%"
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.
来源:https://stackoverflow.com/questions/3316315/distribute-a-database-made-with-javadb-with-java-program