无法连接到SQLite数据库 [英] Can't connect to a SQLite database
问题描述
try {
con = DriverManager.getConnection("jdbc:sqlite:db/Freepark.sqlite");
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("error al buscar la base de datos");
}
我正在尝试在SQL数据库上进行第一次查询,但是连接时遇到问题,我认为问题肯定是URL,项目名称是BaseTest,并且在项目文件夹中有一个名为DB的子文件夹,在里面是Freepark.sqlite.当我运行项目时,出现println消息,因此我知道问题出在URL.在此代码示例上方已经完成了诸如class.forName之类的事情.
I am trying to do my first queries on an SQL database but I am having problems connecting to it, I think the problem is the URL for sure, the project name is BaseTest and inside project folder I have a subfolder called DB and inside it it's Freepark.sqlite. When I run the project the println message appears so I know that the problem is the url. Things like class.forName and so are already done above this code sample.
推荐答案
为什么不尝试输入带有相对路径\的名称,例如:db \ Freepark.sqlite
Why dont you try either putting in the name with the relative path \ like: db\Freepark.sqlite
或也尝试放置sqlite文件的完整路径.
or also try putting the full path of the sqlite file.
您还包括在语句之前以启用sqlite驱动程序,例如:
Also are you including before the statements to enable the driver for sqlite such as:
Class.forName("SQLite.JDBCDriver").newInstance();
或
Class.forName("org.sqlite.JDBC");
这篇关于无法连接到SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!