英文:
How do I get my serch path to a database inside my project to work when not hardcoded?
问题
我写了一个使用数据库的应用程序。数据库已包含在项目中,如果在Netbeans中运行它,则搜索路径有效。如果我尝试独立运行它,使用硬编码的数据库路径可以工作,但使用以下代码无法工作。
我在以下代码部分遇到了问题:
String Map = System.getProperty("user.dir");
String sokVag = Map + ("\\db\\MIBDB.FDB");
System.out.println(sokVag);
mibdb = new InfDB(sokVag);
new InloggningsFonster(mibdb).setVisible(true);
正如您所看到的,我已经打印出了数据库的搜索路径,当我硬编码它时:
mibdb = new InfDB("C:\\Users\\...\\db\\MIBDB.FDB");
完整的搜索路径打印如下:
C:\Users\Carolin\Documents\NetBeansProjects\MIB\db\MIBDB.FDB
这个方式可以工作,但当我写下:
mibdb = new InfDB(sokVag);
它就不能工作。我收到的错误消息是:
无法打开 Firebird 数据库,请检查您的路径。确保在结尾处使用 .FDB
有任何想法吗?
英文:
I've written an app that uses a database. The database is included in the project an the searchway works if you run it in Netbeans. If I try to run it independently it works with a hardcoded path to the database, but not with the following.
I'm having trouble with the following bit of code:
String Map = System.getProperty("user.dir");
String sokVag = Map + ("\\db\\MIBDB.FDB");
System.out.println(sokVag);
mibdb = new InfDB(sokVag);
new InloggningsFonster(mibdb).setVisible(true);
as you can see I've printed the searchway for the database and when I hardcode it:
mibdb = new InfDB("C:\\Users\\...\\db\\MIBDB.FDB");
Full print of searchway reads:
C:\Users\Carolin\Documents\NetBeansProjects\MIB\db\MIBDB.FDB
It works, but when I write:
mibdb = new InfDB(sokVag);
It does not work. And the error message I get is:
> Couldn't open Firebird database, check your path. Make sure to use .FDB in the end
Any ideas way?
答案1
得分: 2
谢谢你的回答,毫无明显原因,在一段时间不使用电脑并且没有改变任何东西之后,它正在工作。
英文:
Thank you for all your answers, for no apperent reason, after not using the computor for a while and not changing anything, it's working.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论