How To Access Csv File Within War Using H2's Csvread() Function/query?
I'm trying to read a CSV file from within a web application (Tomcat 5.5.x) and all I get is 'FileNotFoundExceptions's: dbStatement.executeQuery('SELECT * FROM CSVREAD('csvfile.csv
Solution 1:
Maybe you could try to dynamically build the query, first retrieving the full path with ServletContext.getRealPath("/WEB-INF/classes/csvfile.csv").
Solution 2:
H2 currently doesn't support loading files from the classpath. However, you should be able to get the URL of the resource using:
Stringurl= getClass().getClassLoader().getResource("csvfile.csv").toString();
And then you can use this URL (in my case it's an URL starting with "file:") as follows:
dbStatement.executeQuery("SELECT * FROM CSVREAD('" + url + "');");
(I didn't test this in a web app however)
Post a Comment for "How To Access Csv File Within War Using H2's Csvread() Function/query?"