从文本文件读取数据并插入数据库 [英] Read Data From Text File and Insert To databse

查看:140
本文介绍了从文本文件读取数据并插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想逐行读取文本文件中的数据,并将数据插入数据库的每一行。



我现在想的是读取行按行和每行插入数据库。我在这里问的是有更好的主意吗?比如我们可以做什么来一次插入数据而不是逐行循环并插入记录?我在每天需要存储的文本文件中有大约500行,所以性能是我的问题。

I want to read data from a text file line by line and insert the data in each line in database.

What I'm thinking of now read line by line and at each line insert to database. What I'm asking here is there a better idea to do so? like what can we do to insert data at once instead of looping line by line and insert the record? I have around 500+ lines in the text file that I need to store each day, so performance is my issue here.

推荐答案

这取决于您的具体要求。

如果你需要将一个行存储到一个记录中(例如,如果以后的处理需要),那么你必须逐行插入文本文件(如果您一次读取整个文件可能无关紧要)。

另一方面,如果允许将整个文本文件内容存储到数据库记录中,那么请阅读立即全部罚款,然后将其插入数据库记录。
It depends on your exact requirements.
If you need to store one line into one record (for instance, if required by later processing) then you have to insert line by line the text file (and probably it doesn't matter if you read the whole file once or not).
On the other hand if you are allowed to store the whole text file content into a database record then read the whole fine at once and just insert it into the database record.


这篇关于从文本文件读取数据并插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆