Pass CSV content to an Sqlite table

Asked

Viewed 114 times

1

I have a CSV file with student records. I would like to upload these records to a table aluno in the Sqlite.

How can I perform this operation?

  • For use in English: http://stackoverflow.com/questions/16672074/import-csv-file-to-sqlite-in-android

1 answer

0

You have to pass the dice on to the object first. Then you enter the data into the database. There is a framework for working with the Sqlite.

To pass the data from . CSV to object you will have to read line by line from the CSV and break each row by the data divisor (ex. ;). Take each dice and insert into its object.

Exemplo.

CSV
jose ; turma 301 ; 10 anos
joao ; turma 401 ; 11 anos

Stirng csv = leituraDeArquivoCSV();
List<Aluno> alunos = new ArrayList<Aluno>();

while(data.hasNext()){ 
    Aluno aluno = new Aluno();
    String[] data = csv.split(";");
    aluno.setNome(data[0]); 
    aluno.setTurma(data[1]); 
    aluno.setIdade(data[2]); 

    alunos.add(aluno);
}

Now is to take the object students and save normally.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.