*
The moose likes I/O and Streams and the fly likes write data from database table to a csv file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "write data from database table to a csv file" Watch "write data from database table to a csv file" New topic
Author

write data from database table to a csv file

fioana elegant
Greenhorn

Joined: Oct 06, 2010
Posts: 16
i have following columns in table "tbl_url_response"
campaignId,msisdn,urlResponse,transactionId,chargingPath.

i need to write data from this table into a csv file including column headers.

can some1 help???
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
You could

1. Download JDBC and write an implementation to connect to the db

2. Download JDBCSupport (see link below), which sets all this up for you and provides a useful interface

This enables you to pull data out of the databse, all that is left what you want to do with them.


JDBCSupport - An easy to use, light-weight JDBC framework -
fioana elegant
Greenhorn

Joined: Oct 06, 2010
Posts: 16

that i know.i will reteive data using a select * query but m not so good in file handling.so,i dont know how to write data in comma separated values
Sebastian Janisch wrote:You could

1. Download JDBC and write an implementation to connect to the db

2. Download JDBCSupport (see link below), which sets all this up for you and provides a useful interface

This enables you to pull data out of the databse, all that is left what you want to do with them.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183



how about that ?
fioana elegant
Greenhorn

Joined: Oct 06, 2010
Posts: 16
what will be the path of this out.txt???
prob is to write comma separated fields in file
m trying 2 resolve it..........
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
fioana elegant wrote:
m trying 2 resolve it..........


don't use 2 and whatever abbreviations there might be ;-).

The path you pass to the File constructor is simply the absolute path to the file you are writing to, e.g. C:/Documents/out.txt

Now, separating by comma is simple,

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

If you want to be lazy you can use opencsv (see AccessingFileFormats); CSVWriter has a method writeAll(ResultSet rs, boolean includeColumnNames) that will do all the hard work for you. It's open source so you can even look at the source if you want to know how it works.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: write data from database table to a csv file
 
Similar Threads
java code to export mssql data into csv file
Writing csv files
JDBC Driver
CSV+truncate leading zero solution
Approach to validate objects in list