Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 772
  • Last Modified:

reading a text file and inserting into database

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
Gurpreet Singh Randhawa
Asked:
Gurpreet Singh Randhawa
  • 3
  • 2
1 Solution
 
_agx_Commented:
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
 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
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
 
_agx_Commented:
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
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
 
_agx_Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now