• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to write contents of oracle table into csv file?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm trying to write content of oracle table into a csv file for one of my task.
First i tried to add the column name into csv file followed by writing the column value into the csv file.
But when i try to add my column name to csv file its showing only my last column name value cos its overwriting existing column name value each time.

Can some one help me to solve this issue?

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm confused about what a "column name value" is. I'm also confused about why your code doesn't actually write the contents of the table to the CSV file... is that what you are asking about?

Perhaps it would help if you showed an example of your output and explained why it was wrong?
 
prasanna ganesh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for your reply..

You are right so far i didn't write code to add the table value into my csv file.

Before that i want to add my column name into csv file.

My table value should like below, where first line is my column name and followed below its value.

SKU_CODE SKU_UPC LIST_PRICE SALE_PRICE
XXXXXX YYYYY 36 0
ZZZZZ AAAAA 45 0


Right now with my code i can see only the last column name "SALE_PRICE" in my test.csv file.

PFA for your reference.

 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know who "PFA" is.

Anyway you should do some debugging to see what your code is doing. Wait... I see you already are. But you haven't told us the results of that. Keeping your data secret isn't helpful. Tell us what you already found out.
 
prasanna ganesh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Paul,
I attached my output file with my previous reply. But it was somehow missed... Once again sorry because it was not accepting csv and xls file as attachment.

I hava four columns(sku_code,sku_upc,list_price,sale_price) in my table.

SKU_CODE SKU_UPC LIST_PRICE SALE_PRICE
400567461373 883834147291 36 0
400568822197 400568822197 45 0
400430619481 85447978723 11 0

But with my current code it was only writing sale_price column in my test.csv file because it was overwriting my previous coloumn name values.

SALE_PRICE


I think now you can able to understand my issues.

I'm anticipating a solution from you and let me know where i was wrong with my code.

Thanks again.




 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Anyway you should do some debugging to see what your code is doing. Wait... I see you already are. But you haven't told us the results of that. Keeping your data secret isn't helpful. Tell us what you already found out.

 
prasanna ganesh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

You are not clear with my previous reply? I pasted my output of my actual table values and output which i got.

Let me know if you are not clear.

Actual outuput:

SKU_CODE SKU_UPC LIST_PRICE SALE_PRICE
400567461373 883834147291 36 0
400568822197 400568822197 45 0
400430619481 85447978723 11 0

My output:

SALE_PRICE
 
prasanna ganesh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
Finally i got answer for my question. As you said i did some more debug with my code and modified it slightly to get the expected result for my task.

Thanks for your guidance.

Here is my code

 
Ranch Hand
Posts: 56
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is an API available for this exact functionality. Please see http://opencsv.sourceforge.net/#sql-integration
 
prasanna ganesh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vivek,

Thanks for this.. If i would have got your reply some time earlier itself, it was so useful for my task..

Anyhow i come to know one new api for csv stuff.. Thanks once again.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code has two flaws:
1) it's printing spaces between the first few columns.
2) it won't handle commas inside values well.

I was also going to recommend opencsv; it's designed to handle all these cases, and it has an easy way to write a ResultSet to the CSVWriter.
 
reply
    Bookmark Topic Watch Topic
  • New Topic