有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

用Java程序分发用JavaDB制作的数据库

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

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

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

有什么想法吗

非常感谢


共 (1) 个答案

  1. # 1 楼答案

    我不确定自己是否理解了这个问题,但可以将只读数据库打包到JAR中。从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. 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
    

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