Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


reading a text file and inserting into database

Posted on 2013-06-20
Medium Priority
Last Modified: 2013-07-02
What is the best possible way to read the text file which has around 10000 records and each column is separated by tab or comma and has 10 columns for every single row

what is the best possible way to do it in coldfusion
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 52

Accepted Solution

_agx_ earned 2000 total points
ID: 39263719
The fastest way is letting your db handle the import. It's much faster than using list functions and inserting via cfloop.



MS SQL Example
   FROM 'c:\some\path\yourImportFile.txt'
        FIELDTERMINATOR ='\t',
        ROWTERMINATOR = '\r\n',

MySQL Example
LOAD DATA INFILE 'c:\some\path\yourImportFile.txt'
   INTO TABLE YourTable
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39264917
but what if i needs through a way in coldfusion, i know that will far less slower but right now that may serve the purpose
LVL 52

Expert Comment

ID: 39265765
Both can be used from ColdFusion.  It's no different than any sql command.

If you must parse it manually, there's plenty of examples on parsing CSV files.  The logic is exactly the same for tab delimited files.

* Treat it as a list delimited by new chr(10) chr(13)
* As you loop, split each line into columns using list functions, delimiter "," or chr(9)
* Insert the values into the db

Amazon Web Services EC2 Cheat Sheet

AWS EC2 is a core part of AWS’s cloud platform, allowing users to spin up virtual machines for a variety of tasks; however, EC2’s offerings can be overwhelming. Learn the basics with our new AWS cheat sheet – this time on EC2!

LVL 29

Expert Comment

by:Pravin Asar
ID: 39266827
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39266865
Thanks Guys, I know parsing of text files but i was acquiring info as to how we can do better in coldfusion like fast processing rather than depending upon list
LVL 52

Expert Comment

ID: 39267076
Well like I said above, the fastest method is let the db do the importing.  Both commands can be used in a cfquery.  I do it all the time.

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question