是否可以访问可执行 JAR 之外的 SQLite 数据库文件?
我有一个作为可执行 JAR 文件部署的应用程序。最初,这个 JAR 文件将与 MySQL 数据库通信,但最近我决定改用 SQLite。然而,在测试时我发现从 JAR 文件运行应用程序时无法访问 SQLite 数据库文件。
我使用以下网站的 JDBC 驱动程序: http://zentus.com/sqlitejdbc/index.html
我必须采取解决方法吗?
该驱动程序在我的 Eclipse 环境中测试时工作得很好,但似乎不能在 JAR 文件中独立工作。任何帮助将不胜感激。
I have an application that I deploy as an executable JAR file. Originally, this JAR file would communicate with a MySQL database but recently I have decided I want to go with SQLite instead. However, while testing I found that I could not access my SQLite database file when running my application from the JAR file.
I'm using the JDBC driver from the following website: http://zentus.com/sqlitejdbc/index.html
Is there a workaround I have to do?
The driver works great while testing in my Eclipse environment, but doesn't seem to work standalone in a JAR file. Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这里有一个术语“工作目录”。它是应用程序启动的目录。因此,应用程序中的每个“相对”路径通常都相对于这个“工作目录”。
现在让我们回到你的问题。当您设置文件的路径时,您可以将其设置为相对、绝对或相对于 JAR 内部目录根,具体取决于您创建文件和设置路径的方式。
因此,只需重新检查应用程序中的路径设置方式并尝试使用相关路径,从适当的目录运行应用程序即可。
Well, here is such term as "working directory". It is the directory from where your application is started. So, every "relative" path in your application is usually relative to this "working directory".
Now let's return to your problem. When you set the path to a file you can make it either relative, absolute or relative to the JAR inner directory root, depending how you do create the file and set the path.
So, just recheck how paths are set in your application and try to use the relative one, running you application from the appropriate directory.