1

I am working on a simple program in java, which I use to read and write a few things in one SQLITE database, located within the directory I have the jar file. To access the database and a settings file, I use the

String wd = System.getProperty("user.dir");
String dbName = "jdbc:sqlite:"+wd+"\\"+sqliteDataNae;
c = DriverManager.getConnection(dbName);

Long story short, I have made a jar file wrapping all libraries in and tested it in Windows where everything works fine. I get my data stored in my database. Not exception at all!

Then I transfer all my files in a rar file to an ubuntu (14) hyperv virtual machine. I use the terminal to go to my directory where I have unzipped everything, and run:

java -jar myJar.jar

The script starts running, I get my println and the setting are all loaded (hence no issue reading the settings txt file - located in the same directory as the database = no directory issue), The problem is that I get an sqlite exception [SQLITE_ERROR] SQL error or missing database (no such table: User).

However, I open my database (using SQLite Database Browser) and the table exists.

Is there any logical explanation for this? and is there any solution?

Manos C
  • 333
  • 4
  • 16
  • Does your code check if opening the database actually succeeds? That is not clear from the snippet you posted. – arkascha Mar 17 '16 at 16:28

2 Answers2

3

My guess is since Linux uses forward slashes for path separators you'll need to replace '\\' with '/'. However to make life easier just use File.separator instead as it automatically gives you the default separator for the current OS.

  • Thank you for your answer, this was actually what was going on. Unfortunately i thought that due to the fact that it reads the settings file this would not be an issue. However I reach the settings file in another way (using dir) pathSeparator did not work, however File.separator did :) http://stackoverflow.com/questions/5971964/file-separator-or-file-pathseparator (I suppose it might be good to update your answer and if you have understood something differently please let me know so that I could update my question) – Manos C Mar 17 '16 at 16:44
  • yes you're right, it should be separator not pathSeparator. Cheers. –  Mar 19 '16 at 03:40
0

You should use File.pathSeparator it's used to separate individual file paths (Every OS uses different kind of Path variable).

For windows, it’s ‘\’ and for unix it’s ‘/’.

e.g: File file = new File("abc"+File.separator+"def.txt");

//on Unix system prints: abc/def.txt

M. Mariscal
  • 1,226
  • 3
  • 17
  • 46