javadatabasems-accessjavafxucanaccess

Database file does not exist in Packed Jar File


I have a JavaFX project using MS access as a database, after creating executable JAR in IntelliJ, while running the jar in CMD, i get the following exception

net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.x.x given file does not exist: resource\Account_Record.accdb
    at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:231)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:251)

which indicateds the the database file is not reacheable by my following comection:

Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
        conn = DriverManager.getConnection("jdbc:ucanaccess://resource//Account_Record.accdb);

i have checked the Jar file, and yes it have the "Account_Record.accdb" inside it, and while running the JAR file inside IntelliJ IDE, i get no errors, but not able to make it stand alone !


Solution

  • UcanAccess looks for the database just in the filesystem, you have to extract it by your own code