Search code examples
javaderby

Derby Embedded with SPACE in the database path


I use derby embedded in a desktop app. But when there is a space in the database path (in any level of directories) the derby driver fails to connect to the database.

Regards, :)

update

public static final String connectionUrl = "jdbc:derby:[path]database;user=app;password=pass;";
String path = Utils.getPathOfJar();
String dbPath = connectionUrl.replace("[path]", path);
dbConnection = DriverManager.getConnection(dbPath);

Solution

  • First of all this problem only occurs in Linux.

    The path to the database should be set in the system properties like this:

    derby.system.home

    like this:

    String path = Utils.getPathOfJar();    
    path = path.jarFilePath.replaceAll("%20", "\\ ");
    System.setProperty("derby.system.home", path);
    
    public static final String connectionUrl = "jdbc:derby:database;user=app;password=pass;";
    dbConnection = DriverManager.getConnection(connectionUrl);