Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7913291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:48:27+00:00 2026-06-03T13:48:27+00:00

I am writing a Java app to export data from Oracle to csv file

  • 0

I am writing a Java app to export data from Oracle to csv file

Unfortunately the content of data may quite tricky. Still comma is the deliminator, but some data on a row could be like this:

| ID    |   FN    |   LN   |  AGE   |  COMMENT                   |
|----------------------------------------------------------------|
| 123   |  John   |  Smith |   39   | I said "Hey, I am 5'10"."  |
|----------------------------------------------------------------|

so this is one of the string on the comment column:

I said “Hey, I am 5’10”.”

No kidding, I need to show above comment without compromise in excel or open office from a CSV file generated by Java, and of course cannot mess up other regular escaping situation(i.e. regular double quotes, and regular comma within a tuple). I know regular expression is powerful but how can we achieve the goal with such complicated situation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:48:29+00:00Added an answer on June 3, 2026 at 1:48 pm

    There are several libraries. Here are two examples:


    ❐ Apache Commons Lang

    Apache Commons Lang includes a special class to escape or unescape strings (CSV, EcmaScript, HTML, Java, Json, XML): org.apache.commons.lang3.StringEscapeUtils.

    • Escape to CSV

      String escaped = StringEscapeUtils
          .escapeCsv("I said \"Hey, I am 5'10\".\""); // I said "Hey, I am 5'10"."
      
      System.out.println(escaped); // "I said ""Hey, I am 5'10""."""
      
    • Unescape from CSV

      String unescaped = StringEscapeUtils
          .unescapeCsv("\"I said \"\"Hey, I am 5'10\"\".\"\"\""); // "I said ""Hey, I am 5'10""."""
      
      System.out.println(unescaped); // I said "Hey, I am 5'10"."
      

    * You can download it from here.


    ❐ OpenCSV

    If you use OpenCSV, you will not need to worry about escape or unescape, only for write or read the content.

    • Writing file:

      FileOutputStream fos = new FileOutputStream("awesomefile.csv"); 
      OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
      CSVWriter writer = new CSVWriter(osw);
      ...
      String[] row = {
          "123", 
          "John", 
          "Smith", 
          "39", 
          "I said \"Hey, I am 5'10\".\""
      };
      writer.writeNext(row);
      ...
      writer.close();
      osw.close();
      os.close();
      
    • Reading file:

      FileInputStream fis = new FileInputStream("awesomefile.csv"); 
      InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
      CSVReader reader = new CSVReader(isr);
      
      for (String[] row; (row = reader.readNext()) != null;) {
          System.out.println(Arrays.toString(row));
      }
      
      reader.close();
      isr.close();
      fis.close();
      

    * You can download it from here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a diagram editor in java. This app has the option to export
I'm writing my Java app a update mechnism. I create a windows batch file,exit
I'm writing a java app that creates a pdf from scratch using the pdfbox
I'm writing a java app that reads a File every second using FileInputStream (it's
I'm currently writing a Java app that interfaces with a MySQL database. My problem
i am writing standalone java app for production monitoring. once it starts running the
I'm writing a Java servlet in Eclipse (to be hosted on Google App Engine)
I'm writing an app for Java ME, and I need a class for holding
i am writing a web proxy in java on google App engine.I figured out
I'm fairly new to Java and am writing an app that needs an XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.