使用Java程序分发使用JavaDB创建的数据库 [英] Distribute a database made with JavaDB with Java program

查看:220
本文介绍了使用Java程序分发使用JavaDB创建的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

但是,现在我想用我的JAR文件$ b分发这个填充的JavaDB文件$ b用于分发,因为连接到服务器不是一个选项。

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.

过去我只能用JAR
分配一个空数据库德比套餐。

In the past I could only distribute an empty database with the JAR by using that Derby package.

任何想法?

非常感谢你!

推荐答案

我不确定我是否理解了这个问题但是可以在JAR中打包一个只读数据库。来自derby文档:

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:


在类路径中访问数据库中的内容



一旦创建了包含一个或多个
Derby数据库的存档,就可以将
放在类路径中。这个
允许在一个应用程序中从
访问数据库,而不需要
应用程序知道
存档的路径。当jar或zip文件是
类路径的一部分时,你不需要
指定jar subsubprotocol
来连接它们。

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.

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

To access a database in a zip or jar file in the class path:


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

  1. Set the class path to include the jar or zip file before starting up Derby:

CLASSPATH="C:\dbs.jar;%CLASSPATH%"


  • 连接jar或zip文件中的数据库以下连接URL的

  • 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)
    


  • 例如:

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


    如果没有回答问题,请澄清。

    If this doesn't answer the question, please clarify.

    这篇关于使用Java程序分发使用JavaDB创建的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆