简体   繁体   English

使用Java程序分发由JavaDB创建的数据库

[英]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. 我正在用Java创建一个程序,其中我必须使用很多表。 I made the decision to create all those tables in a JavaDB file. 我决定在JavaDB文件中创建所有这些表。

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. 但是,现在我想将这个填充的JavaDB文件与我的JAR文件一起分发,以进行分发,因为不能选择连接到服务器。

In the past I could only distribute an empty database with the JAR by using that Derby package. 过去,我只能通过使用该Derby软件包来分发带有JAR的空数据库。

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. 我不确定我是否理解这个问题,但是可以在JAR内打包一个只读数据库。 From the derby documentation: 从derby文档中:

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. 创建包含一个或多个Derby数据库的存档后,可以将其放置在类路径中。 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. 如果jar或zip文件是类路径的一部分,则无需指定jar子子协议即可连接到它们。

To access a database in a zip or jar file in the class path: 要在类路径中的zip或jar文件中访问数据库,请执行以下操作:

  1. Set the class path to include the jar or zip file before starting up Derby: 在启动Derby之前,设置类路径以包含jar或zip文件:

     CLASSPATH="C:\\dbs.jar;%CLASSPATH%" 
  2. Connect to a database within the jar or zip file with one of the following connection URLs: 使用以下连接URL之一连接到jar或zip文件中的数据库:

     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. 如果仍不能解决问题,请澄清。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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