是否可以在可执行JAR之外访问SQLite数据库文件? [英] Is it possible to access a SQLite database file outside of an executable JAR?

查看:178
本文介绍了是否可以在可执行JAR之外访问SQLite数据库文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个部署为可执行JAR文件的应用程序.最初,此JAR文件将与MySQL数据库通信,但最近我决定我想使用SQLite.但是,在测试时,我发现从JAR文件运行应用程序时无法访问SQLite数据库文件.

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.

我正在从以下网站使用JDBC驱动程序: http://zentus.com/sqlitejdbc/index.html

I'm using the JDBC driver from the following website: http://zentus.com/sqlitejdbc/index.html

我有解决方法吗?

在我的Eclipse环境中进行测试时,该驱动程序工作得很好,但在JAR文件中似乎不能独立运行.任何帮助将不胜感激.

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.

推荐答案

嗯,这里是工作目录"之类的术语.这是启动应用程序的目录.因此,应用程序中的每个相对"路径通常都是相对于此工作目录"的.

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".

现在让我们回到您的问题.将文件设置为路径时,可以将其设置为相对于JAR内部目录根目录的相对,绝对或相对路径,具体取决于创建文件和设置路径的方式.

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.

这篇关于是否可以在可执行JAR之外访问SQLite数据库文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆