* The table to load the data into.
* @param columns
* The columns to be loaded (optional).
*/
public void loadCopyFile(File copyFile, String tableName, String ... columns) {
CopyManager copyManager;
InputStream inStream = null;
try {
StringBuilder copyStatement;
InputStream bufferedInStream;
Connection conn;
copyStatement = new StringBuilder();
copyStatement.append("COPY ");
copyStatement.append(tableName);
if (columns.length > 0) {
copyStatement.append('(');
for (int i = 0; i < columns.length; i++) {
if (i > 0) {
copyStatement.append(',');
}
copyStatement.append(columns[i]);
}
copyStatement.append(')');
}
copyStatement.append(" FROM STDIN");
inStream = new FileInputStream(copyFile);
bufferedInStream = new BufferedInputStream(inStream, 65536);
conn = DataSourceUtils.getConnection(dataSource);
try {
copyManager = new CopyManager(conn.unwrap(BaseConnection.class));
copyManager.copyIn(copyStatement.toString(), bufferedInStream);
} finally {
DataSourceUtils.releaseConnection(conn, dataSource);
}
inStream.close();