Nerdrium Home



Web Design

Case Mods





My Blog




Import Text to Database Using ColdFusion

by Michael Greifenkamp (July 26th, 2006)

Recently I had a list of e-mail addresses that I needed to import into a database. And using ColdFusion, it was surprisingly simple.

First, I opened my list of e-mail addresses in a text editor and made sure that each address was on its own line. My list happened to be comma-delimited, so I simply did a find-and-replace of a comma for a paragraph return. Then, and this is an important part, I added a single line to the top of the file--just the word "email". I saved the file as "email.txt" and uploaded it to my webserver

Now for the fun ColdFusion part. The easiest way to do this is to use cfhttp. Here's the code (I'll explain it afterwards):

<cfhttp method="get" name="insertEmail" url="">
<cfloop query="insertEmail">
<cfquery datasource="mydatasource" name="qInsertEmail">
INSERT INTO emailList VALUES ('','');

Note that the variable name "email" matches the word I typed at the top of the file I wanted to import, and that the name "insertEmail" is the same in the cfhttp, cfloop, and as the first part of the variable name in the INSERT statment.

The two blank ticks ('') in the list of values assumes some sort of key ID that will increment automatically.

Any questions? Feel free to drop me a line.