File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

write data from database table to a csv file

 
fioana elegant
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fioana elegant
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



how about that ?
 
fioana elegant
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic