Alex
Alex

Reputation: 883

Connecting to HSQL DB from Spring

I start HSQL DB with a Maven plugin (I use the DB in integration tests):

<plugin>
    <groupId>com.btmatthews.maven.plugins.inmemdb</groupId>
    <artifactId>inmemdb-maven-plugin</artifactId>
    <version>1.4.3</version>
    <configuration>
        <monitorKey>inmemdb</monitorKey>
        <monitorPort>11527</monitorPort>
    </configuration>
    <executions>
        <execution>
            <id>run</id>
            <goals>
                <goal>run</goal>
            </goals>
            <phase>pre-integration-test</phase>
            <configuration>
                <daemon>true</daemon>
                <type>hsqldb</type>
                <database>MY_DB</database>
                <username>user1</username>
                <password>111</password>
            </configuration>
        </execution>
        <execution>
            <id>stop</id>
            <goals>
                <goal>stop</goal>
            </goals>
            <phase>post-integration-test</phase>
        </execution>
    </executions>
</plugin>

When the DB is up and running I am able to create a JDBC connection:

Class.forName("org.hsqldb.jdbcDriver");
Connection connection = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:9001/MY_DB", "sa", "");
System.out.print(connection);

This code prints: org.hsqldb.jdbc.JDBCConnection@2d22efc3.

However, when I try to use the same connection settings to configure a data source in Spring, I get an exception (java.net.ConnectException: Connection refused):

<bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
    <property name="url" value="jdbc:hsqldb:hsql://localhost:9001/MY_DB" />
    <property name="username" value="sa" />
    <property name="password" value="" />
</bean>

I also tried username:user1 and password:111, it produces another exception: org.hsqldb.HsqlException: invalid authorization specification - not found: user1.

How can I connect to this DB from Spring?

Upvotes: 0

Views: 1353

Answers (1)

user3360944
user3360944

Reputation: 558

On the advice of counsel, I am adding as answer that your hsql db was not running when you tried to connect from Spring.

Upvotes: 1

Related Questions