Jason
Jason

Reputation: 1431

Connect to Derby Embedded DB with Squirrel

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?

Upvotes: 1

Views: 1903

Answers (1)

Boiler Bill
Boiler Bill

Reputation: 1940

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.

Upvotes: 1

Related Questions