#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    9
    Rep Power
    0

    Can you exprot database records with ColdFusion?


    Hi,
    I'm a beginner with using ColdFusion. I interact with some Oracle tables within my ColdFusion templates and. I need to export the entire contents of AN Oracle table into a text or excel file (or any other format).
    Is there a way to achieve this in ColdFusion?
    Thanks.
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,279
    Rep Power
    968
    You could do this by using a select * from myTable in a cfquery block to get a query containing all the records from that table. Then you could manually loop over the query and write each line to a text file. Or you could use cfwddx to translate the entire result set to XML and write that to a file...there are many options. But the bottom line is yes, this can be done easily.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    9
    Rep Power
    0
    Thanks for replying, kiteless.
    I don't know XML yet, as far as your second solution.
    I've thought of doing this by using your first solution. I thought there might be a built-in feature in CF that does this in an easier way.
    Can you show me the syntax as to how I can write retrieved records into .txt file pelase?
    regards
    spartik
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,279
    Rep Power
    968
    Something like this, depending on your needs:

    Code:
    <cfquery name="myQuery" datasource="myDSN">
    select firstName, lastName from myTable
    </cfquery>
    
    <cffile action="WRITE" file="#getDirectoryFromPath( getTemplatePath() )#/myexportfile.txt" output="">
    <cfoutput query="myQuery">
    	<cffile action="APPEND" file="#getDirectoryFromPath( getTemplatePath() )#/myexportfile.txt" output="#myQuery.firstName# #myQuery.lastName#" addnewline="Yes">
    </cfoutput>

IMN logo majestic logo threadwatch logo seochat tools logo