指定的JDBC驱动程序:org.h2.jdbc - 初始化失败

时间:2014-05-09 11:11:28

标签: jdbc h2

无法连接到数据库。

我还将最新的h2-1.4.178.jar添加到类路径,创建表,通过工具检查连接。

它正常工作,但Tomcat说:“HTTP状态500 - com.vaadin.server.ServiceException:java.lang.RuntimeException:指定的JDBC驱动程序:org.h2.jdbc - 初始化失败。”

我怎么称呼它?我用Eclipse。这是我的src(我使用Vaadin):

try {
        JDBCConnectionPool pool = new SimpleJDBCConnectionPool(
                "org.h2.jdbc",
                "jdbc:h2:~test", "SA", "", 2, 5);
        screen.polulate("TEST", pool);
    } catch (SQLException e) {
        throw new RuntimeException(e);
    } 

我发现了我的问题(https://superuser.com/questions/290999/where-can-i-find-h2-jdbc-driver),但我不明白这是什么意思:

  

然后致电

Class.forName("org.h2.Driver"); 

1 个答案:

答案 0 :(得分:1)

您链接的答案与您的问题无关。问题可能(有根据的猜测)是SimpleJDBCConnectionPool的构造函数的第一个参数需要JDBC驱动程序名称,"org.h2.jdbc"不是JDBC驱动程序名称(&#39} ; s "org.h2.Driver")。

现代JDBC驱动程序不再需要使用Class.forName("org.h2.Driver");。对于旧驱动程序(不包含文件META-INF/services/java.sql.Driver及其驱动程序实现),使用Class.forName("org.h2.Driver");将加载驱动程序,然后驱动程序将使用java.sql.DriverManager注册自己它可以用来创建连接。