Domanda

Sotto il mio metodo del database che sta causando il problema:

 public Cursor fetchRecord(String pin,String category)throws SQLException
{

Cursor c=mDb.query(DATABASE_TABLE, new String[]
{KEY_ROWID,KEY_NAME,KEY_PHONE,KEY_CATEGORY,KEY_PINCODE},
KEY_PINCODE + "= ?" + "AND" + KEY_CATEGORY + "= ?",
new String[]{pin,category}, null, null, KEY_NAME);

    if (c!= null) {
        c.moveToFirst();
    }
    return c;
}
.

ottiene la forza chiusa ogni volta che do input e fai clic sul pulsante Vai nella prima attività Il gatto del registro dice:

Caused by: android.database.sqlite.SQLiteException: near "ANDcategory": syntax error: , while compiling: SELECT _id, name, phone, category, pincode FROM details WHERE pincode= ?ANDcategory= ? ORDER BY name
.

È stato utile?

Soluzione

deve esserci spazio tra il Pincode e la categoria, nella vostra clausola dove.

Sostituisci semplicemente

"AND"
.

con

" AND "


public Cursor fetchRecord(String pin,String category)throws SQLException 
{ 

        Cursor c=mDb.query(DATABASE_TABLE, new String[]
 {KEY_ROWID,KEY_NAME,KEY_PHONE,KEY_CATEGORY,KEY_PINCODE},
KEY_PINCODE + "= ?" + 
" AND " + KEY_CATEGORY + "= ?",new String[]{pin,category}, null, null, KEY_NAME); 

    if (c!= null) { 
        c.moveToFirst(); 
    } 
    return c; 
}
.

Altri suggerimenti

Leggi l'eccezione, ti dice tutto ciò che devi sapere:

syntax error: , while compiling: SELECT _id, name, phone, category, pincode FROM details WHERE pincode= ?ANDcategory= ? ORDER BY name
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top