Android SQLite: How to insert data in to a single column of an existed table
Hallo all,
I have two files, one called "part1.txt" and another one called "part2.txt", which look like following
part1.txt part2.txt
lili like eating apple
lucy like playing football
Now i want to insert the contents of these two files into a single table with the schema
table_name(linefrompart1 varchar(100), linefrompart2 varchar(50))
My program reads the first file line by line and insert the data into the first column. But if it reads the second file and tries to insert the data line by line into the second column, it doesn't work the way i want. A table which i want should look like following
linefrompart1 linefrompart2
lili like eating apple
lucy like playing football
But instead i got the following table
linefrompart1 linefrompart2
lili null
lucy null
null like eating apple
null like playing football
Does som开发者_如何转开发ebody know how i can fix this problem? Thank you!!
You should read both files simultaneously line-by-line and insert the data into the table with a single insert per line.
INSERT INTO table_name (linefrompart1, linefrompart2)
VALUES ('lili', 'like eating apple')
Alternatively if this is not possible then you could add an extra column to your table to store the line number and use an update statement with 'WHERE linenumber = x'.
精彩评论