Android 台灣中文網

標題: 要如何把陣列的數值一筆一筆傳到SQLITE內?? [打印本頁]

作者: gf98110425    時間: 2012-11-27 21:08
標題: 要如何把陣列的數值一筆一筆傳到SQLITE內??
我想說,把JSON的陣列  存到 SQLITE內

可是我不太懂怎麼存進去

因為要存的欄位蠻多,資料比數也蠻多
有點亂,有稍微看過SQLITE的範例
可是 都是直接按下按鈕新增

我想要一次就把陣列內的資料全部存進去
請問一下,我該怎麼做?
或是有啥關鍵字可以告訴我
作者: ploglin    時間: 2012-11-28 09:04
http://stackoverflow.com/questions/754684/how-to-insert-a-sqlite-record-with-a-datetime-set-to-now-in-android-applicatio

SQLiteDatabase.execSQL so you can enter a raw SQL query.
  1. mDb.execSQL("INSERT INTO "+DATABASE_TABLE+" VALUES (null, datetime()) ");
複製代碼
Or the java date time capabilities :
  1. // set the format to sql date time
  2. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  3. Date date = new Date();
  4. ContentValues initialValues = new ContentValues();
  5. initialValues.put("date_created", dateFormat.format(date));
  6. long rowId = mDb.insert(DATABASE_TABLE, null, initialValues);
複製代碼





歡迎光臨 Android 台灣中文網 (https://apk.tw/) Powered by Discuz! X3.1