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');");
I don't think I can/need to specify an absolute path (it will be deployed into a Linux/Tomcat server I won't have access to) and am unsure of the file protocol necessary ('jar:file', classpath: etc).
The file is under "**/WEB-INF/classes/csvfile.csv"
Any ideas on the structure of the path I need to pass to CSVREAD()?
Thanks
Rich
Maybe you could try to dynamically build the query, first retrieving the full path with ServletContext.getRealPath("/WEB-INF/classes/csvfile.csv")
.
H2 currently doesn't support loading files from the classpath. However, you should be able to get the URL of the resource using:
String url = 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)
精彩评论