【问题标题】:How to connect to a database located inside project folder如何连接到位于项目文件夹内的数据库
【发布时间】:2018-01-19 18:09:45
【问题描述】:

也许这是一个愚蠢的问题,但我是数据库新手,我不知道该怎么做。

我使用以下代码行连接到位于我的 D: 驱动器中的数据库。如果数据库位于项目文件夹内,我该如何更改它以便连接到数据库? (我使用 netbeans IDE)

Connection conn = DriverManager.getConnection("jdbc:sqlite:d:\\Databases\\DataBase1.db");
//I don't want an exact path, I need it so it works idependetly of where the project folder is located

【问题讨论】:

标签: java forms server


【解决方案1】:

据此answer

在您的代码中,您可以使用相对路径,它应该相对于项目目录的顶部。在 NetBeans 的数据库服务中,您需要使用绝对路径连接到(在您的项目中)存在的数据库,或者您需要提供相对路径...

所以根据SQLite Tutorial的连接字符串应该如下:

    jdbc:sqlite:DataBase1.db

【讨论】:

    猜你喜欢
    • 2019-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-26
    • 2019-09-26
    相关资源
    最近更新 更多