Link to home
Create AccountLog in
Avatar of illfusion82
illfusion82

asked on

JDBC ResultSet

I have a stored procedure that returns over 8000 rows. I then need to export all the data into a csv file in comma delimited format. When exporting the data into a csv file, the process takes a while. I have to loop through each row to collect all the data. Is there a more efficient or faster way of doing this? Can I just bulk load all the data into the CSV file without having to loop through each row? The database I am connecting to is MSSQL 2005.
ASKER CERTIFIED SOLUTION
Avatar of TempDBA
TempDBA
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of mrcoffee365
It would be much faster to collect all the data in the result set into a Java object of some type, then loop through that to write out your CSV file.

Often the best way to do this is to create a private class just to hold all the elements of one record, then fill a collection (ArrayList, Map, Vector) with those objects.  

>>I have to loop through each row to collect all the data.

That's the case with whatever kind of form you get a cursor in, and that's what a cursor is for.

If your goal is only to produce a csv file, then the way to loop through each row would the way mentioned in the first comment, it being the most direct
Avatar of illfusion82
illfusion82

ASKER

Thanks everyone. I am currently looking at the TempDBAs comment. I think that may work the best for me. I will test it out to see how it works.
Thanks BCP works great. I can output the data to a CSV file as well as tab delimited; this is exactly what I wanted.