【发布时间】:2021-03-26 01:02:46
【问题描述】:
我正在研究一个关于使用数据库的培训项目。主库是MySQL,测试用的是H2,这里有教程:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
application.properties 文件中指定了以下设置:
jdbc:
driverClassName: org.h2.Driver
pool.size.max: 10
statement.timeout: 0
url: jdbc:h2:mem:mytestdb;DB_CLOSE_ON_EXIT=FALSE
username: sa
password:
测试通过,即数据输入数据库,检查,一切OK。
但是当我在调试模式下运行测试时,在测试结束时下一个断点并尝试连接数据库,它是空的,甚至没有表,更不用说数据了。要连接,我使用 Dbever。在连接字符串中,我写了 jdbc:h2:mem:mytestdb;DB_CLOSE_ON_EXIT=FALSE (我试过 jdbc:h2:tcp://localhost:9092/mem:mytestdb)。检查连接通过,写道一切正常,连接建立。可能是什么问题?
我尝试写入文件,而不是 url:jdbc:h2:mem:ump-currencymanager; DB_CLOSE_ON_EXIT=FALSE 我写了: url: jdbc:h2:file:c:\logs\logdb 这个文件是我用Dbever打开的时候创建的,连表都在那里,但是表本身没有数据。
研究了有关此主题的类似问题。
@Test
public void createPeopleTable() throws SQLException {
int count = peopleService.count();
assertEquals(0, count);
peopleService.createPeopleTable();
count = peopleService.count();
assertEquals(34, count);
}
【问题讨论】: