设置远程Derby DB:“找不到合适的驱动程序”错误

时间:2017-04-07 14:28:43

标签: java jdbc derby

我正在尝试为练习设置一个远程Derby数据库。每当我访问硬盘驱动器上的数据库时,以下代码都可以正常运行:

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

然后我将整个derbyDB目录上传到Hostgator托管的网站,通过ping服务器获取其IP并相应地编辑了dbPath var。代码停止工作,好像它甚至看不到数据库。我错过了什么?

2 个答案:

答案 0 :(得分:1)

看起来您的驱动程序类未加载。 尝试在调用DriverManager.getConnection之前加载它,看看它是否有效。

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

答案 1 :(得分:0)

经过一番挖掘后回答我自己的问题

这是我在官方Apache Derby文档(https://db.apache.org/derby/docs/10.0/manuals/develop/develop14.html)中找到的:

  

您只能指定机器本地的数据库   JVM正在运行。

看起来我想要完成的事情无法完成......