2

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;
    }
  }
}
2
  • inside of the catch block, do a line e.printStackTrace(); and post that here. It might help with debugging. Commented Sep 12, 2016 at 18:51
  • @RyanZink no that is the correct way to get a connection from DriverManager. Commented Sep 12, 2016 at 18:53

1 Answer 1

1

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();
    }

}
Sign up to request clarification or add additional context in comments.

4 Comments

open a IDE and write String x = ""; and inside "" paste the contents of the url that you posted above you will notice the weird whitespace that i am talking about it looks like String x = "jdbc:sqlite:\u202A\u202A\u202AC:\\\\Users\\\\chusm\\\\workspace\\\\DBMS\\\\SQlite\\\\DBMS.sqlite"; those invisible unicode characters were the problem
Now I understood, Actually Eclipse was not letting me save or compile the program and asked me if i want to save it using unicode UTF-8 something like this and I saved it this way maybe that created the problem. Thanks a lot for your precious time and help.
![enter image description here](i.sstatic.net/4LHSq.png) @Alexandru this is what I am talking about do you know why this error appears and what does it mean. This error appeared when I initialized a String with my path statement and run the program.
I suspect that the place where you copied the original url from had the strange whitespace or maybe the file explorer where you copied it from. Whenever you get a message like that it's a good hint that you have invisible characters going on and you should inspect the new additions to the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.