On H2 documentation, it says only the web server supports browser connections. Does this mean we can only access the H2 Database by console in WebServer mode, not TcpServer? But when I do below test, the result is totally not as 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 start a TcpServer, I can visit the DB by this url: jdbc:h2:tcp://localhost:9092/mem:test in console.
//Use TcpServer
Server server = Server.createTcpServer().start();
But when I start a WebServer, I tried to connect use jdbc:h2:http ://localhost:8082/mem:test, below exception will throw: IO Exception: "java.io.IOException: The filename, directory name, or volume label syntax is incorrect"; "http ://localhost:8082/mem:test.h2.db" [90031-172] 90031/90031 (Help).
//Use WebServer
Server server = Server.createWebServer().start();
Here are my questions
- Can we access the WebServer mode h2 DataBase in console? How?
- Did I misunderstand the H2 documentation about the Using the Server section?