通过 Java 程序分发由 JavaDB 制作的数据库

发布于 2024-09-11 02:10:44 字数 195 浏览 9 评论 0原文

我正在用 Java 创建一个程序,其中必须使用很多表。 我决定在 JavaDB 文件中创建所有这些表。

但是,现在我想将这个填充的 JavaDB 文件与我的 JAR 文件一起分发 用于分发,因为无法选择连接到服务器。

过去我只能用 JAR 分发一个空数据库 通过使用 Derby 包。

有什么想法吗?

太感谢了!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狼亦尘 2024-09-18 02:10:44

我不确定我是否理解这个问题,但可以将只读数据库打包到 JAR 中。来自德比文档:

访问类路径中的 Databases-in-a-Jar

一旦档案包含一个或多个
Derby数据库已经创建好了
可以放在类路径中。这
允许访问数据库
在应用程序中没有
应用程序知道的路径
档案。当 jar 或 zip 文件是
类路径的一部分,你不
必须指定 jar 子协议
连接到他们。

访问 zip 或 jar 中的数据库
类路径中的文件:

  1. 在启动之前设置类路径以包含 jar 或 zip 文件
    德比:

    CLASSPATH="C:\dbs.jar;%CLASSPATH%"
    
  2. 使用以下之一连接到 jar 或 zip 文件中的数据库
    以下连接 URL:

    jdbc:derby:/databasePathWithinArchive
    
    (标准语法)
    
    jdbc:derby:classpath:/databasePathWithinArchive
    
    (带有子子协议的语法)
    

例如:

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

如果这不能回答问题,请澄清。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文