Site icon Ya Mazaj

How can I export database records to a csv file without using a character delimiter?

I have the code below that does successfully export table data to a csv file. However, the second to last parameter (CHARACTERDELIMITER) in the procedure requires a CHAR(1) entry.

StringBuilder exportBuilder = new StringBuilder("CALL SYSCS_UTIL.SYSCS_EXPORT_QUERY('");
exportBuilder.append(joinQuery.toString()); 
exportBuilder.append("', 'r:/exported_file.csv', NULL, '\u0000', NULL)");
CallableStatement exportStatement = conn.prepareCall(exportBuilder.toString());
exportStatement.execute();

I would like no characters to surround the tokens in the csv file (not counting the COLUMNDELIMITER ‘,’), but the above procedure exports the data with a NUL character surrounding the strings and dates.
The ‘\u0000’ character was used because it worked in a similar import procedure where the data was not surrounded by any characters (not counting the COLUMNDELIMITER ‘,’)
I’ve seen Db2 has a ‘nochardel’ that can be used to achieve what I’m looking for, but I can seem to find the same for Apache Derby. I’d like to use these procedures instead of a BufferedReader. I will be importing/exporting possibly five million records.
Reference link: https://db.apache.org/derby/docs/10.14/ref/rrefexportselectionproc.html

Thanks for any help.

Exit mobile version