• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

java code to export mssql data into csv file

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to export table data from mssql into csv file using java.
I want a query to run it from java class.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the connection to JBoss (which this forum is all about)?
 
Bartender
Posts: 2662
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to our JDBC forum.
 
harikumar meda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jan Cumps wrote:Moved to our JDBC forum.



I dont want JDBC(getting connection and Resultset).
I just want a query to run from java using run command
 
harikumar meda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:What's the connection to JBoss (which this forum is all about)?



there is no connection with Jboss
 
Jan Cumps
Bartender
Posts: 2662
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

harikumar meda wrote:I dont want JDBC(getting connection and Resultset).
I just want a query to run from java using run command

Still the JDBC forum is the best fit for this question
Regards, Jan
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I just want a query to run from java using run command


SQL Server should come with a command line utility that lets you run queries against the database. Hopefully that utility will also let you specify that the output should be to a CSV file. Once you figure out the proper query syntax, and can run the query from the command line, place the command line with a Runtime.exec() call.

The CSV formatting is probably what will be the hard part; the utility might not have that as an output option. Which means you will have to output to a text file and run a script against the text file. You will have to wrap all of this within a script which you invoke via exec().

Or perhaps there is such a utility that will output the CSV for you...

(Then again, you might actually be asking for the syntax for the command line utility, in which case my response hasn't helped any...)
 
harikumar meda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am able to export csv file using bcp command.
But i want it with headers in csv file
 
harikumar meda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jan Cumps what is your JDBC forum?

Exactly what i want is export csv file from mssql table.

Now i am able to get csv file using "BCP". But problem is i am not getting headers.

 
Jan Cumps
Bartender
Posts: 2662
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

harikumar meda wrote:Jan Cumps what is your JDBC forum?

The JDBC forum (this forum) is the location on JavaRanch where we discuss JDBC and SQL related issues.

The JavaRanch has forums for several types of discussions. Depending on the type of question you have, you select the correct forum, and post your question there.

Your post is currently in the JDBC forum.

Regards, Jan
 
Popeye has his spinach. I have this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic