Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
| Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 13th, 2004, 09:35 AM
Registered User
 
Join Date: Oct 2004
Location: chd, punjab, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default save file in csv, txt format in jsp URGENT


 i have a very urgent problem...

i am displaying data from database, MYSQL. and using jsp and tomcat...

i want that when i click on a link name csv or txt then the displayed results are saved in a text or excel format.....

pls help urgent




nidhi
  #2 (permalink)  
Old October 14th, 2004, 04:59 PM
Authorized User
 
Join Date: Oct 2004
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

On the hosting page, set up a link like

<a href="download.jsp">Download as CSV file</a>

then in the new download.jsp file using the same resultset object you used for the grid display do a loop like. I am assuming htat you keep the result set object in a bean or something. Otherwise you'll have to re-run the query.

rs.moveFirst(); // Since you've probably already moved through the entire set on the grid page

// Output the column names
for( int i = 1; i <= rs.getColumnCount(); i++ )
{
  out.println( rs.getColumnName(i) );
}

// Output the data
while( rs.next() )
{
  out.println( rs.getString( "Your Field Name Here" ) +"," + ... repeat for all columns);
}

the browser should take acre of the file transfer part of this


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save a file in CSV format thru Excel VBA macro roli2712 Excel VBA 1 July 11th, 2007 03:05 AM
Get table records into Txt or CSV format kapi.goel SQL Language 0 April 10th, 2006 01:47 AM
save dataset in txt format??? thomaz C# 3 March 20th, 2006 01:29 PM
save as CSV file cdsniti Java Databases 1 December 21st, 2005 07:26 AM
How do I Save a form's contents into a .txt file flyingfox Pro VB.NET 2002/2003 2 March 28th, 2004 01:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.