Solved

reading a text file and inserting into database

Posted on 2013-06-20
6
577 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
  • 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 15

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 28

Expert Comment

by:Pravin Asar
ID: 39266827
0
 
LVL 15

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now