How to insert blob data into Spring embedded HSQLDB via sql script?

This is my sql script creating the database:

create table product 
(id integer identity primary key,
name varchar(50) not null,
price decimal(10,2) not null,
image blob(1024),
category_id integer);

      

This is my sql script that inserts data into the database:

INSERT INTO product VALUES (1, 'ProductName', 699.95, load_file('full_path'), 1);

      

According to HSQLDB, the default full path is the relative path to the database location. So what do I need to provide as the file path for the image files that are in / resources / img /? (Spring builds the DB using this url: jdbc: hsqldb: mem: testdb)

+3


source to share


3 answers


You can get the absolute path of the classpath resource like this:



new ClassPathResource("img/abc.gif").getFile().getAbsolutePath()

      

+1


source


I faced the same problem while setting up tests with HSQLDB . It seems that HSQLDB only supports that only load_file('full_path')

uses absolute file paths .

Alternatively use inline DB configuration on H2 database to achieve the same result.



The same request will be listed below in the H2 config.

INSERT INTO product VALUES (1, 'ProductName', 699.95, FILE_READ('classpath:filename.ext');

      

0


source


See parameter description textdb.allow_full_path

.

It allows you to use a variety of file paths.

-1


source







All Articles