Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hi all I need to save the values f 1

Status
Not open for further replies.

ktsrikanth

Programmer
Feb 6, 2001
22
0
0
US
hi all
I need to save the values from a resultset to a .csv files. please let me know how i do that. Is that the right process to doit from java or i need to doit from database.

Please help me
Thank you
 
Hi, here is a little function that i just made. The only thing that you have to do is to create the FileWriter for the csv and catch the exceptions.

private static void writeResultSet(ResultSet resultSet, Writer output)
throws SQLException, IOException
{
int cols = resultSet.getMetaData().getColumnCount();
while(resultSet.next()) //as long as there are rows
{
/*
for every row, get the content of the cell, and write it.
*/
for(int i =1; i <= cols; i++)
{
output.write(resultSet.getObject(i).toString());
if(i < cols) output.write(&quot;,&quot;);
}
output.write(&quot;\n&quot;);
}
output.close();
}

Hope this helps

Greetings,
Steven.
 
Hi Steven,
Thank you for the mail. There is a small problem here.
The data is not written into the .csv file at all. I am able to output the data onto the browser since i am using the servlets. But, not into the .csv.
What i did is

i opened a excel sheet and saved it as a .csv file. is that right? if not please tell me how to go about the .csv file.

Please help me soon.

Thank you
 
Sorry for this late reply, but i was on a needed vacation for a long weekend.
I've tested the fnuction myself in a servlet and it creates a .csv file in the root of the webserver. Can you send me your servlet so that i can see what the possible problem is?

Greetings,
Steven.
 
Hi steven
Thank you for the script. I have a another problem now.
I am using Apache, Jserv for the servlets to run.
I get an exception IO Exception: Broken Pipe, randomly, whenever i run the servlets.
I do not know the cause for this exception.
Please help me with what might be the cause for the Exception.

Thank you



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top