Как подключить accdb с помощью UcanAccess к приложению Android? - PullRequest
0 голосов
/ 25 июня 2018

Наконец я смог подключиться к sdcard, но теперь я хочу подключиться к БД в общей папке в сети. Я не получаю. Я пробовал несколько способов, и ниже следует мой случай кода. Любая помощь приветствуется.

открытый класс ConnectionClass {

public static Connection conn = null;

public Connection CONN(){
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    String DRIVER = "net.ucanaccess.jdbc.UcanaccessDriver";
    String DbDsn = "jdbc:ucanaccess://";
    String DbServer = "//192.168.15.4";
    String DbPath = "/Banco";
    String DbName = "/DBase.accdb";

    String ConnUrl= DbDsn + DbServer + DbPath + DbName;

    try{
        String caminho_2 = DbServer+DbPath+DbName;
        System.out.println("Caminho - " + caminho_2);

        File teste = new File(caminho_2);
        if(teste.exists()) {
            System.out.println("Arquivo OK");
        }else{
            System.out.println("Não OK");
        }

        try {
            System.out.println("Verificação Driver");
            Class.forName(DRIVER);
        }
        catch(ClassNotFoundException cnfex) {

            System.out.println("Problem in loading or "
                    + "registering MS Access JDBC driver");
            cnfex.printStackTrace();
        }
        System.out.println("Classificando Driver");

        System.out.println("String de conexão - " + ConnUrl);

        conn = DriverManager.getConnection(ConnUrl);

        System.out.println("Conexão Estabelecida");

    }catch (SQLException cnfe){
        System.out.println(cnfe);
        System.out.println("Erro - 1");
    }catch (Exception se){
        System.out.println(se);
        System.out.println("Erro - 2");
    }
    return conn;
}

}

...