H2 createTcpServer()不创建服务器? [英] H2 createTcpServer() does not create server?

查看:999
本文介绍了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).

这篇关于H2 createTcpServer()不创建服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆