Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6601463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:45:21+00:00 2026-05-25T18:45:21+00:00

I am trying to write a program. On of the funktions of the program

  • 0

I am trying to write a program. On of the funktions of the program is to be able to import data form a csv file to a sqlite database.

I have made this code so fare but it is not working properly. My problem is that it will only save the last line of my csv file in the database. What am i missing?

Here are the code

package com.android.FAC;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;



public class Importcsv extends Activity
{


DbAdapter DbHelper;
String notification = "Concats imported!";
TextView tView;

String first;
String last;
String phone;
String mphone;
String room;
String initial; 

public void onCreate(Bundle icicle) 
{
    super.onCreate(icicle);     
    setContentView(R.layout.importcsv);
    DbHelper = new DbAdapter(this);
    DbHelper.open();     
    tView = (TextView) findViewById(R.id.textView1);        
    Button b2 = (Button) findViewById(R.id.btnClick2);
    Button b3 = (Button) findViewById(R.id.btnClick3);  
    Button b4 = (Button) findViewById(R.id.btnClick4);  



    b2.setOnClickListener(new TextView.OnClickListener() {
        public void onClick(View v) {                
            try {
                readfromcsv();

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }
    });

    b3.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            Intent i = new Intent(Importcsv.this, MainActivity.class);
            Importcsv.this.startActivity(i);
    }
    });

    b4.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {

            int n = 0;
            while(n<30)
            {
            DbHelper.deleteContact(n);
            n++;
            }
     }
     });
}

public void readfromcsv() throws IOException
{

    File sdcard = Environment.getExternalStorageDirectory();
    File file = new File(sdcard,"csvtest.csv");

    BufferedReader in = new BufferedReader(new FileReader(file));
    String reader = "";
    while ((reader = in.readLine()) != null)
    {
        String[] RowData = reader.split(",");

        first = RowData[0];
        last = RowData[1];
        phone = RowData[2];
        mphone = RowData[3];
        room = RowData[4];
        initial = RowData[5];   



    }

    DbHelper.createContact(first, last, phone, mphone, room, initial);
    in.close();
    Context context = getApplicationContext();
    int duration = Toast.LENGTH_SHORT;
    Toast toast = Toast.makeText(context, notification, duration);
    toast.show();
}
}

Thanks Peter

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:45:21+00:00Added an answer on May 25, 2026 at 6:45 pm

    Presumably this line:

     DbHelper.createContact(first, last, phone, mphone, room, initial);
    

    belongs inside the while loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a program that takes a large file (of any type)
I trying to write a program that navigates the local file system using a
I have spent quite a while trying to write a program to implement Conway's
I am trying to write a program that allows a binary to be run,
I'm trying to write a program in Python and I'm told to run an
I am trying to write a program that displays the integers between 1 and
I'm trying to write a program with Hibernate. My domain is now complete and
I'm trying to write a program in Java that uses osql to generate a
i am trying to write a program that close explorer then runs another program.
I am trying to write a program that has a vector of char arrays

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.