简体   繁体   中英

Setting up a remote Derby DB: “No suitable driver found” error

I am trying to set up a remote Derby database just for practice. The following code works without a problem whenever I access the DB on my harddrive:

class Test{
    public static void main(String[] args) {
        String protocol = "jdbc:derby:";
//        String dbPath = "C:/Java_Practice/derbyDB";    // this dbPath works...
        String dbPath = "//108.167.141.127/derbyDB";     // and this one doesn't
        String url = protocol + dbPath;
        try( Connection conn = DriverManager.getConnection(url) )
        {
            System.out.println(conn);
        }
        catch(SQLException e){
            System.out.println(e.getMessage());
        }
    }
}

I then uploaded the whole derbyDB directory to my Hostgator-hosted website, obtained its IP by pinging the server and edited the dbPath var accordingly. The code stopped working as if it can't even see the DB. What am I missing?

Looks like your driver class not loaded. Try loading it before calling DriverManager.getConnection, and see if it works.

String driver = "org.apache.derby.jdbc.ClientDriver";
Class.forName(driver).newInstance();
String protocol = "jdbc:derby:";
String dbPath = "//108.167.141.127/derbyDB"+";create=true";
String url = protocol + dbPath;
Connection conn = DriverManager.getConnection(url);

Answering my own question after some digging .

This is what I found in the official Apache Derby documentation ( https://db.apache.org/derby/docs/10.0/manuals/develop/develop14.html ):

You can specify only databases that are local to the machine on which the JVM is running.

Looks like what I wanted to accomplish cannot be done...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM