[英]SQLite Exception Path does not exist
I am trying to connect an already existing SQLite database to my java project, as a temporary solution for testing a simple log-in dialog. 我正在尝试将一个已经存在的SQLite数据库连接到我的java项目,作为测试简单登录对话框的临时解决方案。 Here is my connector class:
这是我的连接器类:
import java.sql.*;
import javax.swing.*;
public class SQLite_login_connector {
//Initializes global connection variable (unused until now!)
Connection conn_log = null;
public static Connection logindb_connection(){
//Simple try catch block that prints error trace log in a JOptionPane if runtime error occurs.
try{
Class.forName("org.sqlite.JDBC");
Connection conn_log = DriverManager.getConnection("jdbc:sqlite:/SQLite/ISRSMS_Login.sqlite");
JOptionPane.showMessageDialog(null, "Connection Successful!");
return conn_log;
} catch(Exception e){
JOptionPane.showMessageDialog(null, e);
return null;
}
}
}
My SQLite database is located in a folder within my project folder: 我的SQLite数据库位于项目文件夹中的一个文件夹中:
When I try running my connector class, it throws the following exception: 当我尝试运行连接器类时,它将引发以下异常:
For me it looks as if it assumes that the folder which contains my database is located on my F: drive, as opposed to my root project in my local repository. 对我来说,似乎假定包含我的数据库的文件夹位于我的F:驱动器上,而不是我的本地存储库中的根项目。 I have tried putting the database into my src folder, as well as into a new resource folder all-together.
我尝试将数据库放到我的src文件夹中,以及一起放到一个新的资源文件夹中。 Every time it throws the same exception.
每次抛出相同的异常。 Why does it do that?
为什么这样做呢?
As you have metntioned / in yor connection string it is pointing to the root directory of your drive Remove the / in your connection string Do as follows 在连接字符串中/后,它指向驱动器的根目录。删除连接字符串中的/请执行以下操作
DriverManager.getConnection("jdbc:sqlite:SQLite/ISRSMS_Login.sqlite")
For your convenience please follow the naming convention of java language http://www.oracle.com/technetwork/java/codeconventions-135099.html 为方便起见,请遵循Java语言的命名约定http://www.oracle.com/technetwork/java/codeconventions-135099.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.