code: public static long exportCSV(final File out, final Connection conn, final String querySQL, final Collection<String> selectColumnNames, final long offset,
              final long count, final boolean writeTitle, final boolean quoted) throws UncheckedSQLException, UncheckedIOException {
          final NamedSQL namedSQL = NamedSQL.parse(querySQL);
          PreparedStatement stmt = null;
  
          try {
              stmt = conn.prepareStatement(namedSQL.getPureSQL(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
              stmt.setFetchSize(200);
  
              return exportCSV(out, stmt, selectColumnNames, offset, count, writeTitle, quoted);
          } catch (SQLException e) {
              throw new UncheckedSQLException(e);
          } finally {
              JdbcUtil.closeQuietly(stmt);
          }
      }
docs: Exports the data from database to CVS.
  
  @param out
  @param conn
  @param querySQL
  @param selectColumnNames
  @param offset
  @param count
  @param writeTitle
  @param quoted
  @return