Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to HSQL which Spring creates when jdbc:embedded-database is used?

Tags:

spring

hsqldb

I have a HSQL database which Spring automatically creates for me:

<jdbc:embedded-database id="dataSource" type="HSQL">
    <jdbc:script location="classpath:scheme.sql" /
</jdbc:embedded-database>

And now I want to connect to this database. My question is how to do this, because I don't known which address I should use.

like image 717
Slava Semushin Avatar asked Jan 16 '12 11:01

Slava Semushin


People also ask

Which of the database is embedded with the spring boot application automatically?

Spring Boot can auto-configure embedded H2, HSQL, and Derby databases.

What are the embedded DB in spring boot?

Spring Boot can auto-configure embedded H2, HSQL and Derby databases. You don't need to provide any connection URLs, simply include a build dependency to the embedded database that you want to use.

What is Hsqldb in memory database?

HSQLDB (HyperSQL Database) HSQLDB is an open source project, also written in Java, representing a relational database. It follows the SQL and JDBC standards and supports SQL features such as stored procedures and triggers. It can be used in the in-memory mode, or it can be configured to use disk storage.


2 Answers

This embedded HSQL database is all-in-memory and in-process, therefore accessible only from the Spring Java process. If you want to access the database from another tool as well, for example to check the contents with a database manager, you can start an HSQLDB server with an all-in-memory instance, then connect to the server from Spring and other tools.

This is covered in the HSQLDB Guide http://hsqldb.org/doc/2.0/guide/listeners-chapt.html

The server is started with this command:

java -cp ../lib/hsqldb.jar org.hsqldb.Server --database.0 mem:test --dbname.0 test

You need to create a Spring data source with username "SA" and password "". The database driver and URL (from the same machine) to configure the Spring data source are:

org.hsqldb.jdbcDriver
jdbc:hsqldb:hsql://localhost/test
like image 162
fredt Avatar answered Nov 15 '22 18:11

fredt


I recomend you to use external Database, but just in case if you want to use HSQL, then this may will help you http://java.dzone.com/articles/spring-3-makes-use-embedded-easy

like image 41
emilan Avatar answered Nov 15 '22 19:11

emilan