How to connect to the WebServer H2 mode database in the console?

The H2 documentation says: only the web server supports browser connections . Does this mean that we can only access the H2 database through the console in WebServer mode, and not TcpServer? But when I do below the test, the result is completely not what I expected.

public class TestMem {
    public static void main(String... args) throws Exception {

        Class.forName("org.h2.Driver");
        Connection conn = DriverManager.getConnection("jdbc:h2:mem:test");
        conn.createStatement().execute("create table test(id int)");

        Server server = Server.createTcpServer().start();//1.TcpServer
//      Server server = Server.createWebServer().start();//2.WebServer

        System.out.println("Server started and connection is open.");
        System.out.println("URL: jdbc:h2:" + server.getURL() + "/mem:test");

        Thread.sleep(5*60*1000);

        System.out.println("Stopping server and closing the connection");
        server.stop();
        conn.close();
    }
}

If I started TcpServer, I can visit the database with this url: jdbc: h2: tcp: // localhost: 9092 / mem: test in the console.

//Use TcpServer
  Server server = Server.createTcpServer().start();

WebServer, , jdbc: h2: http://localhost: 8082/mem: test, : IO Exception: "java.io.IOException: , "; "http://localhost: 8082/mem: test.h2.db" [90031-172] 90031/90031 ().

//Use WebServer
  Server server = Server.createWebServer().start();

  • Web- h2 DataBase ? ?
  • H2 ?
+4
2

H2 Console ( Server.createWebServer) - - -, ( JDBC) - (, Firefox, Google Chrome, Internet Explorer ..).

H2 TCP ( Server.createTcpServer) H2 JDBC. -, -. -.

(-), TCP-, Console, H2 .

URL- : . URL- .

+5

:

"" H2 "... -"

" " , DBeaver Navicat.

, H2 JVM H2 (, , org.h2.Tools.RunScript.execute(...)), " " " H2" H2 H2 TCP-.

( , DBeaver, JVM. H2 DBeaver, JVM DBeaver.)

H2 "test_database" 8085 JVM DB_CLOSE_DELAY = -1 TCP-... - , H2 - :

http://localhost:8085

, , :

Setting Name: Generic H2 (Embedded)
Driver Class: org.h2.Driver
JDBC URL: jdbc:h2:mem:test_database;MODE=MySQL
UserName: {user, e.g. root}
Password: {password, e.g mypassword}

TCP-, H2 .

  • H2 ( JVM JVM)
  • (, DBeaver).

- , , , - " H2":

http://localhost:8085

, , :

Setting Name: Generic H2 (Server)
Driver Class: org.h2.Driver
JDBC URL: jdbc:h2:tcp://localhost:9095/mem:test_database;MODE=MySQL
UserName: {user, e.g. root}
Password: {password, e.g mypassword}

URL

jdbc:h2:tcp://localhost:9095/mem:test_database;MODE=MySQL 

, , DBeaver.

0

All Articles