1

I am working on a Java+Spring project that uses a Derby Embedded DB to run a suite of Junits. I want to be able to query the Embedded DB using Squirrel SQL client instead of accessing it through my junit tests directly. The reason for this is I am dealing with some very complex data structures and querying with an editor will be quite helpful to construct my test cases. When I run my JUnits in debug, I place a breakpoint after the database is initialized and leave it there, meaning the embedded DB is created at this point. Below shows the spring configuration that wires up the DB.

<bean id="targetDataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" />
    <property name="url" value="jdbc:derby:memory:unitTestDB;create=true" />
    <property name="username" value="sa" />
    <property name="password" value="" />
</bean>

Below shows the console output, the DB is loaded fully at this point...

Executing SQL script from class path resource [mydb/create-schema.sql]
Done executing SQL script from class path resource [mydb/create-schema.sql] in 107 ms.
Executing SQL script from class path resource [mydb/create-sequences.sql]
Done executing SQL script from class path resource [mydb/create-sequences.sql] in 403 ms.
Executing SQL script from class path resource [mydb/create-tables.sql]
Done executing SQL script from class path resource [mydb/create-tables.sql] in 3844 ms.
Executing SQL script from class path resource [mydb/create-views.sql]
Done executing SQL script from class path resource [mydb/create-views.sql] in 2118 ms.
Executing SQL script from class path resource [mydb/MY_TABLE.sql]
Done executing SQL script from class path resource [mydb/MY_TABLE.sql] in 1380 ms.

I am using the same driver that my junit suite uses and created an alias that looks like below in Squirrel...

enter image description here

I can create a connection but it seems like Squirrel isn't able to load schemas + tables.

enter image description here

What might I be doing wrong here?

Russ Schultz
  • 2,545
  • 20
  • 22
Jason
  • 1,371
  • 4
  • 21
  • 44

1 Answers1

1

I don't think you can have an embedded instance be accessed by more than one JVM process. Since you have create=true in the URL it created another embedded database for your Squirrel client.

See this answer for more information.

Boiler Bill
  • 1,900
  • 1
  • 22
  • 32
  • Interesting, had a feeling something like that was going on. – Jason Sep 20 '17 at 17:51
  • You're correct about only one JVM instance can mount an embedded database. Imagine two database servers trying to manage the same database-on-disk at the same time. It's the same idea. – BillRobertson42 Oct 18 '17 at 16:33