aspose file tools*
The moose likes Beginning Java and the fly likes Output is an CSV file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Output is an CSV file" Watch "Output is an CSV file" New topic
Author

Output is an CSV file

Leon Keylin
Greenhorn

Joined: Jun 02, 2006
Posts: 5
Not sure if this is the right place to post but how would I go in to a database, get the results and output in to a CSV file. Would I use a specific class?

Thanks in advance!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11419
    
  16

"ethics"

you apparently missed our naming policy on the way in, which we take VERY seriously. You need a real first AND last name, separated by a space. Obviously ficticioius names are also not allowed. Please go here and correct your profile.

thanks
[ June 02, 2006: Message edited by: fred rosenberger ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jody Brown
Ranch Hand

Joined: Nov 09, 2005
Posts: 43
This JDBC tutorial and this Java CSV file manipulation tutorial would be a good place to start.

There are dozens of examples just like this all over the web. The above are two hits I got right off the bat via Google.

In a nutshell, use JDBC to connect to your database and obtain a ResultSet. Iterate over your ResultSet and use either JDBC again, or a straight file output using the Java IO API to generate your CSV file.

Also, I think your name is against the Java Ranch naming policy. You may want to update it before one of the moderators notice. EDIT: Too late.
[ June 02, 2006: Message edited by: Jody Brown ]
Leon Keylin
Greenhorn

Joined: Jun 02, 2006
Posts: 5
I don't see any fields for first and last name in that link.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11419
    
  16

it's your "publicly displayed name".
Leon Keylin
Greenhorn

Joined: Jun 02, 2006
Posts: 5
Jody, thanks.

However, all I am really looking to do is turn the result in to a CSV file.
Jody Brown
Ranch Hand

Joined: Nov 09, 2005
Posts: 43
Like this?
Leon Keylin
Greenhorn

Joined: Jun 02, 2006
Posts: 5
Actually, through your link I think I found the answer:

For storing data or exporting it as a CSV, we can use the fputcsv() function. In connection with a proper header (content-type and content-disposition) it will prompt the user to either open our script output in Excel or save it.


Now to read up on this fputcsv() function.
Leon Keylin
Greenhorn

Joined: Jun 02, 2006
Posts: 5
Originally posted by Jody Brown:
Like this?


That's even better! Thanks very much!


[ June 02, 2006: Message edited by: Leon Keylin ]
 
 
subject: Output is an CSV file