HikariCP-为什么停止tcpserver会删除数据库中的表

时间:2019-06-17 23:03:39

标签: hikaricp

我创建一个内存中的H2-Server,并用示例表填充数据库。然后,我停止服务器,然后启动服务器。之后,似乎删除了数据库。任何人都知道如何避免删除。以下是伪代码:

Server dbServer = Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "9000").start()
HikariConfig config = new HikariConfig();
HikariDataSource = new HikariDataSource(config);
onfig.setJdbcUrl("jdbc:h2:tcp://localhost:9000/mem:TestDB2;MODE=Oracle";

// Crate a sample table
Connection  conn2 = ds1.getConnection())
Statement stmt = conn2.createStatement();
stmt.executeUpdate("CREATE TABLE SCHEMA_REPO " + "(sequence NUMBER, " + " name VARCHAR(100), " + " PRIMARY KEY (sequence))");
String sql = "INSERT INTO SCHEMA_REPO " + "VALUES (100, 'Zara')";
stmt.executeUpdate(sql);
sql = "INSERT INTO SCHEMA_REPO " + "VALUES (200, 'Mahnaz')";
stmt.executeUpdate(sql);

dbServer.stop();
Thread.sleep(1000);
dbServer.start();
Thread.sleep(1000);

// Read from DB Table, gives error - Exception in thread "main" org.h2.jdbc.JdbcSQLException: Table "SCHEMA_REPO" not found; SQL statement:

我试图理解,为什么原来创建的表被删除了?这是预期的行为,还是我缺少一些配置设置?

谢谢你, 艾哈迈德。

0 个答案:

没有答案