Search code examples
javadatabasenetwork-programmingucanaccess

Reading from a Database in a remote Server using UCanAccess and Apache Commons Net


I have a java application that needs to read from a database. I was able to do this simply by using the UCanAccess driver to read .accdb files (Microsoft Access).

public boolean connect()
{
    System.out.println("\n\nconnecting to database......\n\n");
    try { //connect to the database
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            con = DriverManager.getConnection("jdbc:ucanaccess://C:/Users/C92/Desktop/Database1.accdb");
            st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            return true;
        }
        catch(Exception e)
        {
            System.out.println(e);
            return false;
        }
}

I also have a Client program that connects to a server (run by FileZilla) using Apache Commons Net to transfer files from server to the client.

ftpClient = new FTPClient();
    ftpClient.connect(serverName, 21);
    ftpClient.login(user, pass);
    ftpClient.enterLocalPassiveMode();
    ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

The problem begins when I want to read from that database, but this time placed on the server that I am connected to. I don't know how to combine both implementations (Apache Commons Net and UCanAccess) to read a .accdb file in a server.

Please if you are familiar with networking you may be able to help me with this. Thank you!


Solution

  • I am fairly certain that there is no way to have UCanAccess directly open a database file that resides on an FTP server. Even mechanisms like Apache Commons VFS apparently do not offer a way to directly manipulate or convert a remote file into a java.io.File object.

    Therefore you will need to download the database file first, and then include the absolute path of the local copy in the UCanAccess connection URL.