samedi 31 octobre 2015

Android - SQLiteException: near "=": syntax error (code 1)

I am trying to log id from users table and jobname from jobs table using user id

public String[] getUserJob() {

        String selectQuery = "SELECT id FROM " + TABLE_USERS;
        SQLiteDatabase db = this.getReadableDatabase();

        Cursor cursor = db.rawQuery(selectQuery, null);
                 String[] data = null;

        if (cursor.moveToFirst()) {
            do {

                int myid = cursor.getInt(cursor.getColumnIndex("id"));
                Log.d("TAG","myid:-"+myid);   

                String select = "SELECT jobname FROM " + TABLE_JOBS+ "where userid =" +myid;

                Cursor c = db.rawQuery(select, null);
                String[] d = null;

                if (cursor.moveToFirst()) {
                    do {

                        String jname = c.getString(cursor.getColumnIndex("jobname"));                       
                        Log.d("TAG","jobname:-"+jname);

                    } while (c.moveToNext());
                }       

                return d;

            } while (cursor.moveToNext());
        }

        db.close();
        return data;

    }

May I know, where i am doing mistake and to understand what exactly i am trying to do, have a look at this link

Aucun commentaire:

Enregistrer un commentaire