Derby embedded database 'APPDATA' folder not found, Trying to create OS X application .app
Asked Answered
S

2

2

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 enter image description here

APPDATA not found by .jar after creating a Mac OS X application .app 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 dev help,Thanks!

Supercargo answered 15/4, 2016 at 5:51 Comment(0)
A
1

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

  1. arrange to make your CWD be the place where APPDATA is stored, or
  2. allow the user to tell your app where APPDATA is stored and put that in your JDBC Connection URL.
Aciculum answered 15/4, 2016 at 14:3 Comment(4)
Connection connect = null; Path currentRelativePath = Paths.get(""); String s = currentRelativePath.toAbsolutePath().toString(); try { Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); connect = DriverManager.getConnection("jdbc:derby:"+s+"/APPDATA", "xxx", "lxxxxx"); }//I'm using this CWD, But still not working..Supercargo
Dear sir, Its good idea to define dynamic CWD But It still create problem when I'm trying to access my 'abc.app'.Supercargo
Right before that DriverManager.getConnection call, print out "s", as in: System.out.println(s);. Then look to see if that string actually points to the folder where APPDATA is stored. If not, it needs to.Aciculum
But .app show me '/' only the path becomes jdbc:derby://APPDATASupercargo
I
3

As mentioned in my answer here,
In Mac OSX app, location of current working directory of jar can be obtained using

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

Therefore, for connection string, use:

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



Since I don't have access to Mac right now, just verify whether value of pwd ends with '/'. If yes append "APPDATA" instead of "/APPDATA".
Hope this helps!

Inunction answered 17/4, 2016 at 18:30 Comment(0)
A
1

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

  1. arrange to make your CWD be the place where APPDATA is stored, or
  2. allow the user to tell your app where APPDATA is stored and put that in your JDBC Connection URL.
Aciculum answered 15/4, 2016 at 14:3 Comment(4)
Connection connect = null; Path currentRelativePath = Paths.get(""); String s = currentRelativePath.toAbsolutePath().toString(); try { Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); connect = DriverManager.getConnection("jdbc:derby:"+s+"/APPDATA", "xxx", "lxxxxx"); }//I'm using this CWD, But still not working..Supercargo
Dear sir, Its good idea to define dynamic CWD But It still create problem when I'm trying to access my 'abc.app'.Supercargo
Right before that DriverManager.getConnection call, print out "s", as in: System.out.println(s);. Then look to see if that string actually points to the folder where APPDATA is stored. If not, it needs to.Aciculum
But .app show me '/' only the path becomes jdbc:derby://APPDATASupercargo

© 2022 - 2024 — McMap. All rights reserved.