Home>

Step 1:Create the table

create table dlion (
 _id integer primary key autoincrement, content text, questionid integer, answerid integer, [right] integer
);

Step 2:Put the edited text into res/raw/test.txt

Open it with notepad ++ and put a line for each cell that will be placed in the table

Remove trailing spaces and blank lines:press ctrl + h to select a regular expression-find the target:\ s + $replace with empty

Remove leading whitespace:press ctrl + h to select regular expression-find target:^ \ s + replace with empty

Step 3:Open the database

"Android programming method for SD card to read database》

Step Four:Add Data to the Table

public void addcontent () {
 try {
   bufferedreader localbufferreader=new bufferedreader (
     new inputstreamreader (getresources (). openrawresource (
       r.raw.test)));
   db=opendatabase ();
   for (int i=length + 1 ;;i ++) {
    //add question to database
    string questionstr=localbufferreader.readline ();
    if (questionstr == null) {
     localbufferreader.close ();
     db.close ();
     break;
    }
    log.v ("insert", "insert questioncontent" + questionstr
      + "success!");
    db.execsql ("insert into dlion (questionid, content) values ​​(" + i
      + "," "+ questionstr +" ")");
    //Add answer 1 to the database
    string answerstr1=localbufferreader.readline ();
    if (answerstr1 == null) {
     localbufferreader.close ();
     db.close ();
     break;
    }
    log.v ("insert", "insert answercontent1" + answerstr1
      + "success!");
    db.execsql ("insert into dlion (answerid, content) values ​​(" + i
      + "," "+ answerstr1 +" ")");
    //Add answer 2 to the database
    string answerstr2=localbufferreader.readline ();
    if (answerstr2 == null) {
     localbufferreader.close ();
     db.close ();
     break;
    }
    log.v ("insert", "insert answercontent2" + answerstr2
      + "success!");
    contentvalues ​​answercontent2=new contentvalues ​​();
    answercontent2.put ("answerid", i);
    answercontent2.put ("content", answerstr2);
    db.insert ("dlion", "_id", answercontent2);
    //Add answer 3 to the database
    string answerstr3=localbufferreader.readline ();
    if (answerstr3 == null) {
     localbufferreader.close ();
     db.close ();
     break;
    }
    log.v ("insert", "insert answercontent3" + answerstr3
      + "success!");
    contentvalues ​​answercontent3=new contentvalues ​​();
    answercontent3.put ("answerid", i);
    answercontent3.put ("content", answerstr3);
    db.insert ("dlion", "_id", answercontent3);
    //Add answer 4 to the database
    string answerstr4=localbufferreader.readline ();
    if (answerstr4 == null) {
     localbufferreader.close ();
     db.close ();
     break;
    }
    log.v ("insert", "insert answercontent4" + answerstr4
      + "success!");
    contentvalues ​​answercontent4=new contentvalues ​​();
    answercontent4.put ("answerid", i);
    answercontent4.put ("content", answerstr4);
    db.insert ("dlion", "_id", answercontent4);
   }
 } catch (exception e) {
   //todo:handle exception
   e.printstacktrace ();
  }
}
  • Previous Jsp + servlet + javabean complete data paging method complete example
  • Next Share five common Android layout methods