Search code examples
blobhsqldbdbunit

Using BLOB in DBUnit


I have to test a class where we are retrieving data from Oracle, from a XMLTYPE column. We are using BLOB for the casting, because the system is prepared to run in MySQL too:

BLOB salePlanXmlType = (BLOB) jdsLoad.getValueCell(0, "SALEPLAN");

In DBUnit, first we are creating the tables, and then loading data. The loading part was fun, but I managed to load two XML's using the tips found here.

Anyway I can't manage to create a table in DBUnit with a BLOB type. Here's the script I try to execute:

CREATE TABLE TSHT_SALEPLAN
(
  SALEPLANCODE  INTEGER,
  VENDORCODE    VARCHAR(10),
  HOTELCODE     INTEGER,
  SALEPLAN      BLOB
); 

When I run the test with this script, I get the following error:

java.sql.SQLException: Wrong data type: BLOB in statement 
[CREATE TABLE     TSHT_SALEPLAN
(
  SALEPLANCODE  INTEGER,
  VENDORCODE      VARCHAR(10),
  HOTELCODE     INTEGER,
  SALEPLAN      BLOB]
    at org.hsqldb.jdbc.Util.throwError(Unknown Source)
    at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)

Which I don't understand, because BLOB seems to be supported by hsqldb.

If I change the BLOB column definition and use VARBINARY, it works. But then the casting to Blob in my code throws an exception.

Has anybody used BLOB in a create table statement with DBUnit?


Solution

  • The exception is from an old version of HSQLDB (probably 1.8) that does not support BLOB. Use the latest version 2.3.x jar instead.