Distribute a database made with JavaDB with Java program

好久不见. 提交于 2019-11-28 10:13:16

问题


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:

  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.



来源:https://stackoverflow.com/questions/3316315/distribute-a-database-made-with-javadb-with-java-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!