简体   繁体   English

SQLite异常路径不存在

[英]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数据库位于项目文件夹中的一个文件夹中:

SQLite数据库的项目文件夹

When I try running my connector class, it throws the following exception: 当我尝试运行连接器类时,它将引发以下异常:

带有Eception e的JMessageDialog打印

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

Why is your URL .sqllite? 为什么您的URL .sqllite? I would expect .db - like here 我希望.db- 像这里

jdbc:sqlite:C:/mydir/mydb.db

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQLite异常列不存在 - SQLite exception column does not exist android sqlite异常:列'satze'不存在 - android sqlite exception: column 'satze' does not exist SQLite - 当数据库不存在时未捕获executeUpdate异常? (JAVA) - SQLite - executeUpdate exception not caught when database does not exist? (Java) SQlite列不存在 - SQlite column does not exist SQLite数据库不存在Android - SQLite Database Does Not Exist Android Android SQLite表不存在 - Android SQLite table does not exist 根据Java应用程序不存在SQLite数据库 - SQLite database does not exist according to Java application 嵌套异常是 java.io.FileNotFoundException: 类路径资源 [config/simpleJob.xml] 无法打开,因为它不存在 - nested exception is java.io.FileNotFoundException: class path resource [config/simpleJob.xml] cannot be opened because it does not exist 嵌套异常是 java.io.FileNotFoundException: class 路径资源 [my-config.xml] 无法打开,因为它不存在 - nested exception is java.io.FileNotFoundException: class path resource [my-config.xml] cannot be opened because it does not exist 无法加载bean类; 嵌套的异常是java.io.FileNotFoundException:无法打开类路径资源,因为它不存在 - Failed to load bean class; nested exception is java.io.FileNotFoundException: class path resource cannot be opened because it does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM