Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Output is an CSV file

 
Leon Keylin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12266
36
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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 ]
 
Jody Brown
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any fields for first and last name in that link.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12266
36
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's your "publicly displayed name".
 
Leon Keylin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jody, thanks.

However, all I am really looking to do is turn the result in to a CSV file.
 
Jody Brown
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like this?
 
Leon Keylin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jody Brown:
Like this?


That's even better! Thanks very much!


[ June 02, 2006: Message edited by: Leon Keylin ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic