Chaudary Usman Chaudary Usman - 2 months ago 13
SQL Question

java.sql.SQLException Path to 'path' does not exist

I am writing this because I created a simple Login GUI App to test sqlite database as I am a student of Database Systems and new to it, I used java through eclipse, whenever I run the Application this message "java.sql.SQLException path to c:user//path does not exist"

Error Screenshot

I have searched a lot on google but couldn't find the solution there is a similar question on stackoverflow but there were not enough answer related to my problem, I want to know how to change the code to make the Application work and connect to database?

Any help will be much appreciated.Thanks

Here is the code:

package dbms;

import java.sql.*;
import javax.swing.*;

public class dbConnection {

Connection conn = null;

public static Connection dbConnector(){

try{
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:‪‪‪C:\\Users\\chusm\\workspace\\DBMS\\SQlite\\DBMS.sqlite");
JOptionPane.showMessageDialog(null, "Connection Successful!!!");
return conn;
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
return null;
}
}
}

Answer

It looks like you've got some weird whitespace action going on in your url (between "jdbc:sqlite" and "C:"

Please copy paste this exact code in your project and run it (I only removed the weird whitespace, the rest is exactly like your code)

package dbms;

import javax.swing.*;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;

public class StackOverflowExample {

    Connection conn = null;

    public static Connection dbConnector() {

        try {
            Class.forName("org.sqlite.JDBC");
            Connection conn = DriverManager.getConnection("jdbc:sqlite:C:\\Users\\chusm\\workspace\\DBMS\\SQlite\\DBMS.sqlite");
            JOptionPane.showMessageDialog(null, "Connection Successful!!!");
            return conn;
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
            return null;
        }
    }

    public static void main(String[] args) {
        Connection connection = dbConnector();
    }

}