1

I have looked at every possible answer on this site, nothing quite covers the issue.

I followed a tutorial and tried using the Firefox SQLite Manager AND using the SQLite3 shell to create the same database.

public class DBConnector {
    static Connection conn = null;
    public static Connection connect()
     {
       try{
         Class.forName("org.sqlite.JDBC");
         conn = DriverManager.getConnection("jdbc:sqlite:‪C:\\Users\\John\\Desktop\\database.db");
         return conn;
       }
    catch(Exception e){
        e.printStackTrace(System.out);
        return null;
        }
     }
  }

Whenever I run this i get:

java.sql.SQLException: path to '‪C:\Users\John\Desktop\database.db': 'C:\Users\John\Documents\NetBeansProjects\JBook\‪C:' does not exist

I'm new enough to this to where I have no idea what the issue is. Any help is greatly appreciated. And yes, I have looked at all of the other questions posted and tried using their answers, to no avail.

Thanks again

EDIT: A couple of the possible answers already listed have included to change the .db extension to .sqlite This did NOT work. Another simply showed how to use an absolute path, once again, I had that covered and it didn't work. Another talked about JUnit test and some issue they were having which was irrelevant to what I am doing

ZJC
  • 47
  • 1
  • 9
  • 1
    Whence is the path in the error output `C:\Users\John\Documents\NetBeansProjects\JBook\‪C:`? – Tim Biegeleisen Oct 25 '16 at 05:36
  • Did you create and already open the db? – Donald Wu Oct 25 '16 at 06:08
  • To Tim: that path is the where my project is stored. But being perfectly honest, I have no idea what the additional "C:" is doing at the end of it. That is just the error message being outputted, so i figured I should include it. To Donald: I created it using the sqlite3 shell. When trying to open it, it didnt work so I recreated the same file using the firefox SQLite manager, got the same issue. When accessing the db from the sqlite3 shell, it works just fine, but not when I'm trying to access it via the java app – ZJC Oct 25 '16 at 06:25
  • 1
    Simply because it doesn't use absolute path but relative. So the path use your project location + the path you gave. Might need to use slash instead – AxelH Oct 25 '16 at 07:05
  • Possible duplicate of [Java: Missing Database error](http://stackoverflow.com/questions/14998695/java-missing-database-error) – AxelH Oct 25 '16 at 07:09
  • I have tried using the solutions posited in the aforementioned question thread. None have done anything fruitful. – ZJC Oct 25 '16 at 07:28

1 Answers1

1

Finally got the issue:

Copy the path you specified in notepad++ and set encoding to ansi and you will see some special character before C: which is causing issue .

conn = DriverManager.getConnection("jdbc:sqlite:‪C:\\Users\\ravi\\Desktop\\database.db");
conn = DriverManager.getConnection("jdbc:sqlite:C:\\Users\\ravi\\Desktop\\database.db");
gladiator
  • 1,249
  • 8
  • 23
  • I'm doing a copy/paste with the filepath from the file explorer. Case sensitivity shouldn't be the issue. – ZJC Oct 25 '16 at 06:32
  • Also, I should have admin rights, but on the off-chance that I don't, wouldn't that come up as some sort of denial-of-permission? I'm not sure why the program would break and say that the file doesn't exist over saying that I don't have RWX permissions? – ZJC Oct 25 '16 at 06:34
  • I guess its also worth noting that I saved the file to the desktop as well. I'm not sure why it works for you and not for me. – ZJC Oct 25 '16 at 06:36
  • I have been doing all of this coding in NetBeans. I'm not sure if you're insinuating that I've been using Notepad++ or if using Notepad++ would somehow make a difference (assuming I changed the encoding). Could you be a little more specific as to what you mean? ALSO: Thanks for the help. You are paying attention to the issue. Its much appreciated. – ZJC Oct 25 '16 at 07:27
  • it means that while copying the path some extra characters are added to it ,which may not be seen in normal editor but while using that string it will be considered ,your code will work if instead of copy you write the path specially sqlite:C:\ part. Try it and let me knwo if still it throws same error – gladiator Oct 25 '16 at 07:40
  • I rewrote the filepath manually without doing a copy and paste and that did in fact seem to fix the issue. I'm getting other issues, but I'm assuming that's because of my other code. – ZJC Oct 25 '16 at 07:57