I created sqlite database table and i would like to populate the database table with a CSV file saved in the sd card. my question is, is there any method or approach to insert the entire csv file into the sqlite database at once instead of inserting it line by line?
Asked
Active
Viewed 212 times
-2
-
where is your csv file in sdcard or assets folder – Naveen Tamrakar Feb 25 '16 at 09:54
-
yes first u read csv file using csvreader in android than u insert data in database there is not any directed way to read and save data in database – Naveen Tamrakar Feb 25 '16 at 10:04
-
This link appears to cover what you are asking [Is it possible to insert multiple rows at a time in an SQLite database?](http://stackoverflow.com/questions/1609637/is-it-possible-to-insert-multiple-rows-at-a-time-in-an-sqlite-database) – MikeT Feb 25 '16 at 10:05
1 Answers
0
This is not possible right away unless you use a tool like SQLiteDatabaseBrowser:
If this is not working for you, you can follow the following steps to implement your own import:
- open the file with
FileOutputStream
to read its contents - read the first line (headers) and
STring.split()
items by,
- build an
insert
SQL String based on the items/headers - create a
PreparedStatement
from it - read all subsequent lines and
String.split()
values by,
- assign bind variables
- execute your
PreparedStatement
It's not very difficult and if you don't need the right or best fitting data type that's all.
Good luck!

Trinimon
- 13,839
- 9
- 44
- 60