字段错误的错误请求

时间:2012-07-03 21:34:42

标签: android sqlite

name = namebox.getText().toString();
db.open();
Cursor c1 = db.executequery("SELECT _id FROM " + DATABASE_TABLE_CUSTOMER + " where name='" +name+"'" );
_id = c1.getInt(c1.getColumnIndex("name"));
Cursor c2 = db.executequery("SELECT amount FROM " + DATABASE_TABLE_CUSTOMER
        +
        " where _id=" + _id);
Double amount = c2.getDouble(c2.getColumnIndex("amount"));
Cursor c3 = db.executequery("SELECT arrear FROM " + DATABASE_TABLE_CUSTOMER + " where CUSTOMER_ID =" + _id);
arrear = c3.getDouble(c3.getColumnIndex("arrear"));
db.close();

这给了我一个错误的字段错误请求。我的适配器上的executequery方法如下所示:

public Cursor executequery(String query) throws SQLException
{
    Cursor mCursor = db.rawQuery(query, null);
    if(mCursor != null){
        mCursor.moveToFirst();
    }
    return mCursor;
}

任何人都可以告诉我我做错了什么。我是新人。

1 个答案:

答案 0 :(得分:0)

在处理Cursor1时你是不一致的。 getColumnIndex("name")无法成功,因为ID正在被选中,而不是名称。它应该是getColumnIndex("_id")