CREATE TABLE
hindibible(ID INTEGER PRIMARY KEY AUTOINCREMENT ,
Book INTEGER ,
Chapter INTEGER ,
Version INTEGER ,
TB TEXT ,
NKJ TEXT );
我正在创建sqlite表并插入所有值。在上面的sqlite表中如何将NKJ字段数据存储到arraylist中。
答案 0 :(得分:1)
我使用这些方法。有几点需要注意:
代码:
private String rowValues(ArrayList<String> rowdata) {
StringBuilder valString = new StringBuilder();
String separator = "";
valString.append("(");
for (String cell : rowdata) {
valString.append(separator + "'" + cell.replace("'", "''") + "'");
separator = ",";
}
valString.append(")");
return valString.toString();
}
public void insertArrayList(SQLiteDatabase db, String Table, ArrayList<ArrayList<String>> tabledata) {
Cursor cols = db.rawQuery("select * from " + Table + " limit 0",null);
db.beginTransaction();
try {
db.execSQL("delete from " + Table);
int Xtra = cols.getColumnCount() - tabledata.get(0).size();
for (ArrayList<String> item : tabledata) {
for (int a=0;a<Xtra;a++) {item.add("");}
db.execSQL("insert into " + Table + " values " + rowValues(item) + ";");
//Log.i("insertArrayList","insert into " + Table + " values " + rowValues(item) + ";");
}
db.setTransactionSuccessful();
} catch (Exception e) {
Log.e("DBWrapper", "insertArrayList error: " + e.getMessage());
} finally {
db.endTransaction();
}
}