2016-06-13 25 views
0

我真的不知道为什么我的查询给出一个错误,每件事看起来不错,但logcat显示msg语法error.please检查家伙什么worng在我的查询。rawQuery有什么问题?

public class ContactDatabase extends SQLiteOpenHelper { 
    SQLiteDatabase db; 
    public static final String DATABASE_NAME="totalContact1.db"; 
    public static final String TABLE_NAME="mecontact1"; 
    public static final String NAME="name"; 
    public static final String PHONE="phone"; 
    public static final String UID="_id"; 


    public ContactDatabase(Context context) { 
     super(context, DATABASE_NAME, null, 1); 

    } 

    @Override 
    public void onCreate(SQLiteDatabase db) { 
     try { 
      db.execSQL("create table mecontact1" + 
        "(_id integer primary key , name text, phone text)"); 
     }catch(android.database.SQLException e){ 
       System.out.println("table create nhi ho rha"); 
     } 
    } 
public Cursor forEditPurpose(int pos){ 

     db=this.getReadableDatabase(); 
     Cursor res = db.rawQuery("SELECT, " + UID + ", name, phone FROM mecontact1 where " + UID + " = " + pos + "", null); 
    return res; 

    } 
} 

logcat的状态是:

Caused by: android.database.sqlite.SQLiteException: near ",": syntax error (code 1): , while compiling: SELECT, _id, name, phone FROM mecontact1 where _id = 1 
+2

'“SELECT”'这是错误的 – pskink

回答

1

从该行删除第一个 “” SELECT

Cursor res = db.rawQuery("SELECT, " + UID + ", name, phone FROM mecontact1 where " + UID + " = " + pos + "", null); 

这将是

Cursor res = db.rawQuery("SELECT " + UID + ", name, phone FROM mecontact1 where " + UID + " = " + pos + "", null); 
+0

跆拳道感谢兄弟你节省我的时间 –

+0

你是受欢迎的,但适当的感谢沃尔德可以接受的答案:-) –

1

更改如下:

Cursor res = db.rawQuery("SELECT, " 
    + UID + ", name, phone FROM mecontact1 where " 
    + UID + " = " + pos + "", null); 

要:

Cursor res = db.rawQuery("SELECT " 
    + UID + ", name, phone FROM mecontact1 where " 
    + UID + " = " + pos + "", null);