I am trying to create a Mac OS X application from java desktopos.jar, where my application .jar file using derby embedded database APPDATA. It creates problem when, I'm createing a Mac OS X application .app
Here is my connection method on java(Already working on .exe and setup-Windows & Linux)
public static Connection getdataconnet() {
Connection connect = null;
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
connect = DriverManager.getConnection("jdbc:derby:APPDATA", "xxxx", "xxxxxxxxxxxxxxx");
} catch (ClassNotFoundException ex) {
globalData.GlobalDataSetGet.OLD_USER = -1;
////JOptionPane.showMessageDialog(null, "1"+ex);
} catch (SQLException ex) {
globalData.GlobalDataSetGet.OLD_USER = -1;
////JOptionPane.showMessageDialog(null, "2"+ex);
}
return connect;
}
Mac OS X application architecture .app
APPDATA not found by .jar after creating a Mac OS X application .app
Using CWD..
Connection connect = null;
Path currentRelativePath = Paths.get("");
String s = currentRelativePath.toAbsolutePath().toString();
try {//DriverManager.getConnection("jdbc:derby:"+System.getProperty("user.dir")+"/APPDATA", "#####", "#############");
connect = DriverManager.getConnection("jdbc:derby:"+s+"/APPDATA", "#####", "#############");
} catch (ClassNotFoundException ex) {
globalData.GlobalDataSetGet.OLD_USER = -1;
JOptionPane.showMessageDialog(null, "1"+ex);
} catch (SQLException ex) {
globalData.GlobalDataSetGet.OLD_USER = -1;
JOptionPane.showMessageDialog(null, "2"+ex);
}
The JDBC Connection URL jdbc:derby:APPDATA
says to look for the folder named APPDATA in the current working directory (CWD) of your application.
You need to figure out what your CWD is when your app is launched, perhaps by looking at the answers to this question: Getting the Current Working Directory in Java
Then either