我有一個問題,數據沒有被插入到數據庫中,因爲錯誤日誌說沒有這樣一個名爲columntotal的列存在,這是真的,但是columntotal是我想要傳入的一個變量名爲「購買」的表格稱爲「總計」。我有插入語句構造錯誤嗎?數據沒有插入到SQLite數據庫
public double calculateTotal() {
double columntotal = 0;
Cursor cursor1 = db.rawQuery(
"SELECT SUM(price) FROM purchases", null);
if(cursor1.moveToFirst()) {
columntotal = cursor1.getDouble(0);
}
cursor1.close();
return columntotal;
}
public void insertTotal() {
db.rawQuery("INSERT INTO purchases(total) VALUES(columntotal)", null);
}
INSERT'不是查詢。使用'execSQL'。 –