Derby "APPDATA" embedded database storage not found while trying to create OS X.app application

I am trying to create a Mac OS X application from java desktopos.jar, where is the file of my .jar application using derby, the built-in APPDATA database. This creates a problem when I create a Mac OS X.app application

Here is my java connection method (already running on .exe and setup-Windows and 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.app Application Architecture enter image description here

APPDATA not found .jar after creating Mac OS X.app application enter image description here

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

enter image description here Need help, thanks!

+2
source share
2 answers

The JDBC connection URL jdbc:derby:APPDATAtells you to search for a folder named APPDATA in the current working directory (CWD) of your application.

, CWD, , , : Java

  • , CWD , APPDATA,
  • , APPDATA, URL- JDBC.
+1

,
Mac OSX ,

System.getProperty("java.library.path")

:

String pwd = System.getProperty("java.library.path");
connect = DriverManager.getConnection("jdbc:derby:"+pwd+"/APPDATA", "#####", "#############");



Mac , , pwd '/'. , "APPDATA" "/APPDATA".
, !

+3

All Articles