lundi 11 janvier 2016

Access Denied, Java Cannot create JDBC sqlite database in Program Files

I have put my Java application into an installer using Inno Setup ( url: http://ift.tt/Aa86ZT )

The installer works good but when I try to open my .jar I get the following error:

java.sql.SQLException: opening db: 'AppDB.sqlite': Access is denied

When I was running the build of my .jar from output folder or when I was compiling inside intellIj I didn't encounter those kind of problems, the db would have been creating succesfully.

I am creating my database as this:

public AppDB() {
    Connection c = null;
    Statement stmt = null;
    try {
        DriverManager.registerDriver(new org.sqlite.JDBC());
        c = DriverManager.getConnection("jdbc:sqlite:AppDB.sqlite");

        stmt = c.createStatement();
        String sql = "CREATE TABLE IF NOT EXISTS config (id INTEGER PRIMARY KEY, Directory TEXT NOT NULL UNIQUE)";
        stmt.executeUpdate(sql);

        stmt.close();
        c.close();
    } catch ( Exception e ) {
        System.err.println( e.getClass().getName() + ": " + e.getMessage() );
        System.exit(0);
    }
    System.out.println("Opened database successfully");
}

Aucun commentaire:

Enregistrer un commentaire