Daniel
Daniel

Reputation: 2500

Start HSQLDB database manager on application startup?

Is it possible to start the HSQLDB Database manager automatically somehow when I´m working in my local dev environment? I´m using the in-memory DB at the moment. I found some code to start the database manager when running test cases. Can this be used when starting a web application as well?

org.hsqldb.util.DatabaseManagerSwing.main(new String[] { "--url","jdbc:hsqldb:mem:moviecollection", "--noexit" });

Upvotes: 0

Views: 4581

Answers (3)

Benjamin Muschko
Benjamin Muschko

Reputation: 33436

I am assuming you are using Spring because you tagged your question with it. You could create a Spring bean that has a method that is annotated with the JSR-250 annotation @PostConstruct. Method annotated with @PostConstruct indicates that the method should be invoked after the bean has been created and dependency injection is complete.

@Component
public class Initializer
{
    @PostConstruct
    public void init()
    {
       org.hsqldb.util.DatabaseManagerSwing.main(new String[] { "--url","jdbc:hsqldb:mem:moviecollection", "--noexit" }); 
    }
}

If you would start the DatabaseManagerSwing with a web application it would get created and displayed on the server your WAR is running on which you probably don't want to do.

Upvotes: 3

Michael Pralow
Michael Pralow

Reputation: 6630

if you use maven try exec java program, bind it to the deploy goal

i am sure there are similiar solutions for ant based projects

Upvotes: 0

Ralph
Ralph

Reputation: 120811

You did not need to start it explicite. It is enougth if you configure the connection url and add the jars.

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
  <property name="url" value="jdbc:hsqldb:mem:demo"/>
  <property name="username" value="sa"/>
  <property name="password" value=""/>      <
</bean>

Upvotes: 0

Related Questions