c++ - How can I write data from txt file to database? -
if have txt number of rows , column (number of columns unknown @ beginning, columns separated tab), how can export data database? have managed iterate through first row count number of columns , create table accordingly need go through each row , insert data respective column. how can that?
example of txt file:
name size population gdp aa 2344 1234 12 bb 2121 3232 15 ... ... .. .. .. .. .. ..
the table has been created:
create table random id int, name char(20), size int, population int, gdp int
the difficult part reading in text fields. according definition, field titles separated spaces. true text fields?
a generic process is:
create sql create statement header text. execute sql statement. while reading line of text doesn't fail parse text variables. create sql insert statement using field names , values variables. execute sql statement. end-while
another solution convert txt file tab or comma separated fields. check database documentation see if there function loading files , discover characters used separating columns.
if need specific help, please ask more specific or detailed question.
Comments
Post a Comment