I have written a simple program for myself which works with an Access database file. I used the absolute path to connect to the db:
String path = "jdbc:ucanaccess://D:/Development/20_Eclipse/Budget/data/Budget.accdb";
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
this.conn = DriverManager.getConnection(path);
When I use the runnable jar somewhere else this path (understandably) doesn't work. So I tried relative paths but they didn't work either.
Then I tried to build the path using
String path = "jdbc:ucanaccess://" + helper.programmPathForDB() + "/data/Budget.accdb";
where helper.programPathForDB()
does this:
public String programmPathForDB()
{
String tempPath = this.getClass().getResource( "." ).toString();
String path = tempPath.substring(6, (tempPath.length()-12));
return path;
}
This works ONLY when I start the program through my IDE (Eclipse). When I start the jar somewhere else it doesn't work.
How can I resolve this issue?