Hi,
I am trying to write a utility which will keep reading CSV files from
a particular folder and keep dumping the contents into an in-memory H2
table. The files will have the timestamp in their file names to help
uniquely identify a file.
If I know the file name and path, I can write a simple script like -
insert into TABLE1 (select * from csvread ('FileName')) ;
Now since the filenames will keep changing per file, I need to have a
way in which I can dynamically specify the fileName in the csvread
parameter.
I tried a few things -
1. I created a PreparedStatement with the following sql -
insert into TABLE1 (select * from csvread ('?')) ;
The problem is that the csvread function tries to execute this while
creating the prepared statement itself.
Even if it did manage to create a prepared statement, and then I
specify the parameter to the PreparedStatement using -
preparedStatement.setString(1, actualFileNameString) ;
It says that the parameterIndex 1 is invalid.
I even tried with parameterIndex as 0. But that too it shows as
invalid.
2. I even tried the ? without the quotes as following - insert into
TABLE1 (select * from csvread (?)) ;
In this case the statement does not parse during the preparedstatement
creation step itself.
I am now thinking of reading the sqlString in the code myself and
replacing the ? with the actual file name and then using the new sql
String to execute.
Just wanted to check if there is a better way to this.
If not, then adding support for dynamic params for csvread should be a
useful feature.
Regards,
Vipul.
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.