Home > ColdFusion, MySQL > Load data into MySQL from pipe delimited file using ColdFusion 8

Load data into MySQL from pipe delimited file using ColdFusion 8

December 17th, 2008

An example that will show you how to load mutiple rows of data in a pipe delimited text file into mysql using ColdFusion cfquery. The cfquery sql is standard sql and should be used in any sql script for mysql 5.

The script below will check to see if the file exists. If the file exists, then it will load the data into the table called ‘t00pipe’ using a cfqery tag. This tag accepts most if not all mysql standard query language.

<cfif fileExists('C:/ColdFusion8/wwwroot/myweb/data/mydata.csv') EQ true>
     <cfquery name="loadData" datasource="localtest">
	LOAD DATA LOCAL INFILE 'C:/ColdFusion8/wwwroot/tygate.com/cfc/mydata.csv'
         INTO TABLE test.t00pipe
	FIELDS TERMINATED BY '|'
	IGNORE 1 LINES;
     </cfquery>
</cfif>

LOAD DATA INFILE ['Path to csv'] INTO TABLE [Your Table]

The table columns must match exactly with each column in the delimited file

for more information, please see mysql documentation

ColdFusion, MySQL ,

  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.