2

I got an exception below when trying to use derby in memory database in JUNITTEST.

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);
}
o-90
  • 17,045
  • 10
  • 39
  • 63
stewchicken
  • 463
  • 1
  • 8
  • 20
  • 1
    I assume the exception is occuring in your tearDown() method? It is normal for "drop=true" to throw a "Database dropped" exception. Is that what your question is about? – Bryan Pendleton Oct 14 '15 at 23:54

1 Answers1

0

If you are using Maven for your build, you can use the derby-maven-plugin, which I wrote and is available on GitHub and via Maven Central. It will take care of starting and stopping the database for you before your tests.

You can check here for my answer to a similar question.

Community
  • 1
  • 1
carlspring
  • 31,231
  • 29
  • 115
  • 197