• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

write data from database table to a csv file  RSS feed

 
Greenhorn
Posts: 16
  • 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???
 
Ranch Hand
Posts: 1183
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



how about that ?
 
fioana elegant
Greenhorn
Posts: 16
  • 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
  • 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,

 
Sheriff
Posts: 21466
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!