gpt4 book ai didi

junit - derby内存数据库+ junit

转载 作者:行者123 更新时间:2023-12-02 09:46:20 27 4
gpt4 key购买 nike

当尝试在JUNITTEST的内存数据库中使用derby时,出现以下异常。

java.sql.SQLNonTransientConnectionException: Database 'memory:testDB' dropped. at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)


@Before
public void setUp() throws Exception {
String driver = "org.apache.derby.jdbc.EmbeddedDriver";
String connectionURL = "jdbc:derby:memory:testDB;create=true";
Class.forName(driver);
Connection conn = DriverManager.getConnection(connectionURL);
super.setUp();
}

@After
public void tearDown() throws Exception {
String connectionURL = "jdbc:derby:memory:testDB;drop=true";
DriverManager.getConnection(connectionURL);
}

最佳答案

如果您正在使用Maven进行构建,则可以使用derby-maven-plugin,它是我编写的,可以在GitHub和Maven Central上找到。在测试之前,它将为您启动和停止数据库。

您可以检查here以获取我对类似问题的答案。

关于junit - derby内存数据库+ junit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33129725/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com