Distribute a database made with JavaDB with Java program

拜拜、爱过 提交于 2019-11-29 16:15:16

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.

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