Solved

reading a text file and inserting into database

Posted on 2013-06-20
6
618 Views
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
0
Comment
[X]
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
6 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 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.

* BULK INSERT - MS SQL
* LOAD DATA - MySQL

[Edit]

MS SQL Example
BULK INSERT YourTable
   FROM 'c:\some\path\yourImportFile.txt'
   WITH
     (
        FIELDTERMINATOR ='\t',
        ROWTERMINATOR = '\r\n',
      );

MySQL Example
LOAD DATA INFILE 'c:\some\path\yourImportFile.txt'
   INTO TABLE YourTable
   FIELDS TERMINATED BY '\t'
   LINES TERMINATED BY '\r\n'
0
 
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
0
 
LVL 52

Expert Comment

by:_agx_
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

http://www.experts-exchange.com/searchResults.jsp?searchTerms=ColdFusion+loop+CSV&searchType=10
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 29

Expert Comment

by:Pravin Asar
ID: 39266827
0
 
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
0
 
LVL 52

Expert Comment

by:_agx_
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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