Hello! I am having a problem. So I need to make my program a runnable .jar file. The problem is my SQLite database path.
When I do this line of code the .jar program works fine, but only on my machine: conn = DriverManager.getConnection("jdbc:sqlite:/home/user/eclipse-workspace/LibrarySystem-master/LibrarySystem-master2/SE-Lib-System-master2/SELibSys2/LibraryDB2.db");
The default obviously isnt working: conn = DriverManager.getConnection("jdbc:sqlite:LibraryDB 2.db");
My connection to the database is in a separate class, in case that matters. I have tried many things. This gives me an error: "jdbc:sqlite::resource:LibraryDB2.db"
Also, which runnable jar option should I pick in eclipse? Extract libraries to generated JAR, package libraries in generated JAR, or copy libraries into sub folder? I dont think I want the sub-folder one - this might be doing something I have been selecting package libraries in generated JAR.
Getting errors like this: [SQLITE_ERROR] SQL error or missing database (no such table: Users) - It has to be something with the connection to the database because like I said it works fine on my end with the absolute path but on others machines its not working. I do understand why this is happening but I thought that when I created the runnable jar in eclipse it would pick up the database automatically.
import java.sql.*; import javax.swing.*; // Below is the connection class that is used to connect to the database public class SqlConnection { public static Connection dbConnect() { Connection conn = null; try { Class.forName("org.sqlite.JDBC"); // The database is located in this file path conn = DriverManager.getConnection("jdbc:sqlite:LibraryDB2.db"); return conn; } catch(Exception e) { JOptionPane.showMessageDialog(null, e); return null; } } }
What can I do about this? The database is in the root and also the same folder as the source code.
Thanks.