example to help learn -- you can get a LOT of performance improvements by
moving file IO away from CF. It was designed for CF V 4.5 and hasn't been
tested in MX.
Save this code as a file named "query2csv.java", compile it to
query2csv.class and use it as:
<cfx_query2csv query="" filename="">
PLEASE don't has me how to compile the java -- check java.org
AND
PLEASE don't ask me how to configure CFAdministrator to execute this tag,
see the docs for your specific version.
**************************************************
/* import com.allaire.cfx.CustomTag;
import com.allaire.cfx.Query;
import com.allaire.cfx.Request;
import com.allaire.cfx.Response; */
import com.allaire.cfx.*;
import java.io.FileWriter;
import java.io.IOException;
public class query2csv implements CustomTag
{
public void processRequest( Request request, Response response )
throws Exception
{
//get query structure
Query qMyQuery = request.getQuery() ;
if ( qMyQuery == null )
{
throw new Exception(
"Missing QUERY parameter. " +
"You must pass a QUERY parameter in " +
"order for this tag to work correctly." ) ;
}
//number of rows
int nNumRows = qMyQuery.getRowCount() ;
// Get the list of columns from the query
String[] columns = qMyQuery.getColumns() ;
int nNumColumns = columns.length ;
/* debug print
response.write( "Query has " + nNumRows + " rows and " + nNumColumns +
" Columns" ) ;
*/
String strFileName = request.getAttribute("filename");
FileWriter t o_file = new FileWriter(strFileName);
try {
// Write column headers
for( int i=0; i<nNumColumns; i++ )
{ to_file.write( columns[i] + "," ) ; }
to_file.write( "\n" ) ; /* write end of line character */
// loop through rows and columns writing each out
for( int iRow=1; iRow<=nNumRows; iRow++ )
{
for( int iCols=1; iCols<=nNumColumns; iCols++ )
{
to_file.write( "\"" + qMyQuery.getData( iRow, iCols ) + "\"");
/* if this is not the last column add a comma */
if ( iCols != nNumColumns) to_file.write( "," ) ;
} /* end for loop through columns */
to_file.write( "\n" ) ; /* write end of line character */
} /* end for loop through rows */
} /* end try */
// Always close the file, even if exceptions were thrown
finally {
if (to_file != null)
try { to_file.close(); }
catch (IOException e) { ; }
} /* end finally * /
} /* end processRequest method */
} /* end query2csv class */
-----Original Message-----
From: Lists2 - TriPointTek [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 30, 2003 8:43 AM
To: CF-Talk
Subject: Re: Java Custome Tag
Craig Dudley wrote:
> I've got loads, you just after the format? There's a JAVA CFX section
> in the help which covers most things, and includes some hello world
> cfx's which should help.
I want to integrate a few into CF in conjunction with learning Java.
Thanks
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

