java - sqlserverbulkcopy-export to CSV

csv java performance sqlbulkcopy sql-server-2008

Question

I have a requirement like read bulk data from sql server database through java and write to CSV. Have to use the same CSV to import the data into database.Is there an option with sqlserverbulkcopy class to generate CSV file? We can write plain java code to write CSV,but I may have huge data. I see that there is an option to read from CSV and bulk copy to database.

Popular Answer

Using the BULK INSERT statement we can insert bulk data into the database directly from a CSV file. The simplest version of the BULK INSERT query looks like that:

BULK INSERT dbo.TableForBulkData
FROM 'C:\BulkDataFile.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)

Also, you can read more here: How do I use Java to read a .csv file and insert its data into SQL Server?




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why