Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify url of jdbc:embedded-database

I want to specify the URL for the jdbc:embedded-database tag. Is this not possible?

For example, if I have the following in my context:

<jdbc:embedded-database type="HSQL" id="dataSource">
    <jdbc:script execution="INIT" location="classpath:com/example/init.sql" />
</jdbc:embedded-database>

It will create an in memory database located at jdbc:hsqldb:mem:dataSource

What I want to do is be able to have a different bean ID and database name...

For example:

<jdbc:embedded-database type="HSQL" id="dataSource" url="jdbc:hsqldb:mem:testdb">
    <jdbc:script execution="INIT" location="classpath:com/example/init.sql" />
</jdbc:embedded-database>
like image 349
FGreg Avatar asked Jun 26 '13 18:06

FGreg


People also ask

What is embedded database in spring boot?

H2 is an embedded, open-source, and in-memory database. It is a relational database management system written in Java. It is a client/server application. It stores data in memory, not persist the data on disk.

What is the difference between JDBC and Spring JDBC?

The Spring JDBC Template has the following advantages compared with standard JDBC. The Spring JDBC template allows to clean-up the resources automatically, e.g. release the database connections. The Spring JDBC template converts the standard JDBC SQLExceptions into RuntimeExceptions.

What is meant by embedded database?

An embedded database system is a database management system (DBMS) which is tightly integrated with an application software; it is embedded in the application.

Can we use JDBC and JPA together in spring boot?

NO! Hibernate will execute the SQL statement as it is.


1 Answers

Instead of using jdbc:embedded-database, you can do it with a normal datasource configuration, and spring support for SQL script execution

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


<jdbc:initialize-database data-source="dataSource">
    <jdbc:script location="classpath:schema_h2.sql" />
 </jdbc:initialize-database>
like image 175
Ralph Avatar answered Oct 12 '22 17:10

Ralph