Android SQLite insert multiple records

放肆的年华 提交于 2019-12-04 16:29:05

As in SQL you can insert more than row you can making your string like that

INSERT INTO 'tablename' ('column1') VALUES
('val1'),
('val2'),
('val2'),
('val2');

and here implementation of insertion code :

public void diff_date(View v){
    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
    String insertRows = "INSERT INTO 'tablename' ('column1') VALUES";
     String date_in = sdf.format( dateAndTime .getTime() );
     String date_out = sdf.format( dateAndTime1.getTime() );
     int differenza_date = Days.daysBetween(new DateTime(date_in), new DateTime(date_out)).getDays();
     for(int i=1 ; i < differenza_date ; i++)
     {
         // increase i day each time and save it in string 
         insertRows += "("+increasedDate+"),"
     }

     // and here insert into database 
     db.execSQL(insertRows)
     }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!