1
votes

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);
1
Could you please show way which you pass Database path into Derby driver. - Taky
What is your path? Is it absolute or relative? - Bill
What operating system? What version of Java? What is the exception you get? What is the stack trace from that exception? The more information you provide, the better answer you will get. I've used database paths with spaces in them many times, so there are solutions, but you'll have to give more details in order to get the best help. - Bryan Pendleton
I have already found the solution. The problem happens only in Linux and while I get the path of the JAR file on run-time. So the spaces will convert to "%20" characters. - ehsun7b

1 Answers

0
votes

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);