Skip to content
Advertisement

Load CSV file located in the classpath for H2 Database

For tests purposes, I want to create and fill some tables using SQL scripts as well as CSV files.

So I created a SQL script like this one:

JavaScript

The foo.csv file exists, and is located in src/test/resources.

When this script is run on Eclipse (where src/test/resources is defined as a source directory and thus is included in the classpath), I get the following error:

JavaScript

What did I do wrong? How to use correctly the classpath: protocol to load a CSV file?

If I put the complete path for the file (like ... CSVREAD('C:my-projectsrctestresourcesfoo.csv');), then it works. But that’s not why I want to do 🙂

Note that I use the latest version of H2 (1.3.153) as I wanted to use the classpath: protocol to load my file.

Advertisement

Answer

Even if the official docs give the CSVREAD('classpath:/org/acme/data/address.csv') example, Sean Patrick Floyd suggested to remove the leading slash, i.e. having:

JavaScript

and this is working!

Advertisement