I have very recent code that works in a JUnit test case.
@Test
public void test()
{
final String DATABASE = "jdbc:derby:memory:sampledb;create=true";
final String USERNAME = "sa";
final String PASSWORD = "sa";
final String CREATE_TABLE = "CREATE TABLE names ( oid INT
GENERATED ALWAYS AS IDENTITY, name VARCHAR( 20 ) )";
final String INSERT_NAME1 = "INSERT INTO names ( name ) VALUES (
'Jack' )";
final String QUERY = "SELECT oid, name FROM names";
Connection connection = null;
try
{
connection = DriverManager.getConnection( DATABASE, USERNAME,
PASSWORD );
Statement statement = connection.createStatement();
...
In /pom.xml/, I have the following:
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>*derby*</artifactId>
<version>10.15.2.0</version>
<scope>test</scope>
</dependency>
I only want to use Derby _in-memory_ backing some unit test cases that
need a database (not requiring a running server or dæmon, etc.). It all
works perfectly inside IntelliJ IDEA.
However, when I build from the command line (mvn clean package), I see
this and can find no solution:
java.sql.SQLException: No suitable driver found for
jdbc:derby:memory:sampledb;create=true
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at
com.imatsolutions.database.ApacheDerbyTest.testDirectlyToDerby(ApacheDerbyTest.java:78)
In /pom.xml/, I have tried adding the following, and I have tried many
other solutions, some of which are supposed to be obsolete (
Class.for(...), DriverManager.registerDriver( ... ), etc. ), but cannot
find a happy solution.
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>*derbyclient*</artifactId>
<version>10.15.2.0</version>
<scope>test</scope>
</dependency>
Any comment would be welcome.
Thanks.