h2无法以编程方式启动

时间:2015-12-16 17:39:44

标签: java h2 h2db

我写了以下代码:

  private static void startH2(){
        Server server = null;
        try {
            server = Server.createTcpServer("-tcpAllowOthers").start();
            Class.forName("org.h2.Driver");
            Connection conn = DriverManager.
                    getConnection("jdbc:h2:tcp://localhost/~/test;MODE=PostgreSQL", "sa", "");
        } catch (Exception e) {
            LOG.error("Error while initialize", e);
        }
        System.out.println("finish");
    }
    public static void main(String [] args){
        startH2();
    }

我运行我的main方法并看到以下情况:

enter image description here

看起来Server.createTcpServer创建了新的非守护程序线程。

但是通过网址localhost:8082我看不到h2网络控制台(实际结果 - ERR_CONNECTION_REFUSED

如何解决这个问题?

P.S。

我注意到了url

http://localhost:9092/

我的浏览器downlods文件包含奇怪的内容:

enter image description here

如果要解码此文本,我会看到以下消息:

  

版本不匹配,驱动程序版本为“0”,但服务器版本为“15”

我使用的是h2版本1.4.182

1 个答案:

答案 0 :(得分:1)

H2 contains multiple servers

您已启动TCP服务器。如果要使用浏览器,还需要启动Web服务器:

{{1}}