2016-06-13 4 views
0

私は本当に私のクエリがエラーを出す理由は何も分かりませんが、logcatはmsg構文error.pleaseをチェックしてみてください。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

WTFのおかげで、あなたは私の時間 –

+0

適切おかげで:-)答えを受け入れることがウォールドかかわらず、あなたが、歓迎されているの保存BRO –

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); 
関連する問題