SQLiteException:没有这样的列:

时间:2014-07-20 08:06:49

标签: android sqlite

以下是第一次创建表格的代码....

private void createTables(){

    SQLite ioclData=this.openOrCreateDatabase(Global.DB_NAME, MODE_PRIVATE, null);
    ioclData.execSQL("CREATE TABLE IF NOT EXISTS houses(name TEXT,location TEXT,category TEXT,city TEXT,phone TEXT);");
    try{
        c = ioclData.rawQuery("select * from houses where name="+"Darjeeling", null);
        c.moveToFirst();
    }
    catch(Exception e){

        ContentValues cv = new ContentValues();
        cv.put("name","Darjeeling");
        cv.put("location", "ABCD");
        cv.put("category", "asdqwed");
        cv.put("city", "dqwedcx");
        cv.put("phone", "qdxcc");
        ioclData.insert("houses", null, cv);
    }
}

我在这里试图访问数据......

private void showDetails(){

    c = ioclData.rawQuery("SELECT * FROM houses WHERE name="+home_selc, null);
    c.moveToFirst();
    location.setText(c.getString(c.getColumnIndex("location")));
    category.setText(c.getString(c.getColumnIndex("category")));
    city.setText(c.getString(c.getColumnIndex("city")));
    phone.setText(c.getString(c.getColumnIndex("phone")));
}

访问数据部分给我这个logcat错误.....

android.database.sqlite.SQLiteException:没有这样的列:大吉岭(代码1):,同时编译:select * from houses where name = Darjeeling

1 个答案:

答案 0 :(得分:1)

试试这个:

android.database.sqlite.SQLiteException: no such column: Darjeeling (code 1): , while compiling: select * from houses where name=Darjeeling

查询正在将大吉岭编译为我们需要放置单引号的列(' Darjeeling'),以便编译时将其理解为表达式,而不是作为列,就像做事情一样,加入表。

c = ioclData.rawQuery("select * from houses where name="+"'Darjeeling'", null);