Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use HSQLDB in Oracle query syntax mode?

Tags:

hsqldb

I am trying to use HSQLDB as an embedded database in a spring application (for testing). As the target production database is Oracle, I would like to use HSQLDBs Oracle syntax mode feature.

In the Spring config I use

<jdbc:embedded-database type="HSQL" id="dataSource">
</jdbc:embedded-database>

<jdbc:initialize-database data-source="dataSource" enabled="true">
    <jdbc:script location="classpath:schema.sql"/> 
</jdbc:initialize-database>

And in schema.sql at the top I wrote:

SET DATABASE SQL SYNTAX ORA TRUE;

However, when running my test, I get the following error:

java.sql.SQLException: Unexpected token: DATABASE in statement [SET DATABASE SQL SYNTAX ORA TRUE]

Is this a syntax error or a permissions error or something entirely different?

Thanks - also for any pointers that might lead to the answer.

Given that HSQL is the Spring default for jdbc:embedded-database and given the target is Oracle, this scenario should actually be very common. However, I found nothing on the Web even touching the issue.

Update:

The issue above is resolved thanks to answer #1.

However, I now get another exception:

org.springframework.dao.DataAccessResourceFailureException: Failed to populate database; nested exception is java.sql.SQLException: java.lang.RuntimeException: unsupported internal operation: StatementCommand unsupported internal operation: StatementCommand

Any idea what this is caused by?

like image 235
Jan Algermissen Avatar asked Jan 02 '11 15:01

Jan Algermissen


People also ask

How do I find the HSQLDB content?

You can run H2 web server within your application that will access the same in-memory database. You can also access the H2 running in server mode using any generic JDBC client like SquirrelSQL. UPDATE: Server webServer = Server.

What does HSQLDB mean?

HSQLDB (Hyper SQL Database) is a relational database management system written in Java. It has a JDBC driver and supports a large subset of SQL-92, SQL:2008, SQL:2011, and SQL:2016 standards.

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 option was introduced with HSQLDB 2.0.

Are you sure you are using the correct version?
Maybe you have 1.8 still in the classpath somewhere.

But that won't get you far in terms of testing anyway, because this only turns on some basic syntax "replacing", there is no real behaviour change involved here (and I'm not even talking about more advanced Oracle features like analytical functions, CONNECT BY or something similar).

It is very seldom a good idea to test your application with a DBMS that will not be used in production. It is simply not a valid test.

like image 120
a_horse_with_no_name Avatar answered Sep 28 '22 08:09

a_horse_with_no_name


Even if it only change some basic syntax here is an example of how you can do it:

<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:PUBLIC;sql.syntax_ora=true" />
    <property name="username" value="sa" />
    <property name="password" value="" />
</bean>
like image 32
borjab Avatar answered Sep 28 '22 09:09

borjab