Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java code to export mssql data into csv file

 
harikumar meda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the connection to JBoss (which this forum is all about)?
 
Jan Cumps
Bartender
Posts: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to our JDBC forum.
 
harikumar meda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
  • 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: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic