[英]How to connect to a database located inside project folder
Maybe it's a silly question, but I am new to databases and I don't know how to do this. 也许这是一个愚蠢的问题,但是我是数据库的新手,我也不知道该怎么做。
I have the following line of code that I use in order to connect to a database located in my D: drive. 我使用以下代码行来连接到位于D:驱动器中的数据库。 How can I change it so it connects to the database if the database is located inside the project folder?
如果数据库位于项目文件夹中,如何更改它以使其连接到数据库? (I use netbeans IDE)
(我使用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
According to this answer : 根据这个答案 :
In your code you can use a relative path and it should be relative to the top of your project's directory.
在您的代码中,您可以使用相对路径,它应该相对于项目目录的顶部。 In NetBeans' Databases Service you will need to either use an absolute path to connect to the database that exists (in your project) or you will need to provide a relative path...
在NetBeans的数据库服务中,您将需要使用绝对路径来连接到(在您的项目中)存在的数据库,或者您需要提供相对路径...
So according the SQLite Tutorial connection string should be as follows: 因此根据SQLite Tutorial的连接字符串应如下所示:
jdbc:sqlite:DataBase1.db
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.