读完H2 documentation ,我编写了这个简单的应用程序来在本地目录中创建 H2 数据库:
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 版本)
最佳答案
您需要实际访问数据库,文件是延迟创建的:
server.start();
DriverManager.getConnection(connection);
server.stop();
在中间添加的行会在预期位置创建 tata.h2.db
文件(使用 1.3.155 测试)。
关于java - H2 createTcpServer() 不创建服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8068843/