H2 createTcpServer() does not create server?

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

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();  } 

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

回答1:

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

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

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!