*
The moose likes JDBC and the fly likes java code to export mssql data into csv file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java code to export mssql data into csv file" Watch "java code to export mssql data into csv file" New topic
Author

java code to export mssql data into csv file

harikumar meda
Greenhorn

Joined: Jan 25, 2010
Posts: 8
how to export table data from mssql into csv file using java.
I want a query to run it from java class.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41604
    
  55
What's the connection to JBoss (which this forum is all about)?


Ping & DNS - my free Android networking tools app
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

Moved to our JDBC forum.


OCUP UML fundamental and ITIL foundation
youtube channel
harikumar meda
Greenhorn

Joined: Jan 25, 2010
Posts: 8
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

Joined: Jan 25, 2010
Posts: 8
Ulf Dittmer wrote:What's the connection to JBoss (which this forum is all about)?


there is no connection with Jboss
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

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

Joined: May 14, 2008
Posts: 5823
    
    7

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...)


JBoss In Action
harikumar meda
Greenhorn

Joined: Jan 25, 2010
Posts: 8
I am able to export csv file using bcp command.
But i want it with headers in csv file
harikumar meda
Greenhorn

Joined: Jan 25, 2010
Posts: 8
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

Joined: Dec 20, 2006
Posts: 2497
    
    8

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java code to export mssql data into csv file