H2 createTcpServer()不创建服务器?

问题描述:

在阅读了H2 文档后,我写了这个简单的应用程序来创建H2数据库在本地目录中:

after reading the H2 documentation, I wrote this simple application to create a H2 database in a local directory:

public static void main(String[] args) throws SQLException {

    String path = "C:/Temp/H2/";
    File fpath = new File(path);

    fpath.mkdirs();
    FileUtils.recursiveDelete(fpath);

    String dbName = "tata";
    String connection = "jdbc:h2:file:" + path + dbName;

    Server server = Server.createTcpServer(connection);

    server.start();
    server.stop();

}

这个程序运行正常,但是当我检入目标目录,数据库不存在...(我使用的是版本1.3.161)

This program runs fine, but when I check in the target directory, the database is not there... (i am using release 1.3.161)

数据库,文件创建懒惰:

You need to actually access the database, files are created lazily:

server.start();
DriverManager.getConnection(connection);
server.stop();

中间添加的行创建 tata.h2.db file where expected(testing with 1.3.155)。

Added line in the middle creates tata.h2.db file where expected (tested with 1.3.155).