Als Parameter eine Konstante übergeben?

M

Mintmaroo

Neues Mitglied
0
Hallo,

folgendem Code möchte ich als Parameter die Konstante Tabelle übergeben, da ich steuern möchte, aus welcher Tabelle er Daten sucht/löscht whatever.

PHP:
 Vermittler getContact(int id, String Tabelle) {
        SQLiteDatabase db = this.getReadableDatabase();
 
        Cursor cursor = db.query(Tabelle, new String[] { KEY_ID,
                KEY_NAME, KEY_PH_NO }, KEY_ID + "=?",
                new String[] { String.valueOf(id) }, null, null, null, null);
        if (cursor != null)
            cursor.moveToFirst();
 
        Vermittler contact = new Vermittler(Integer.parseInt(cursor.getString(0)),
                cursor.getString(1), cursor.getString(2));
        // return contact
        return contact;
    }
 
Die Oncreate Methode des DatabaseHandlers sieht wie folgt aus, es werden zwei Tabellen erstellt.

PHP:
public void onCreate(SQLiteDatabase db) {
        String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
                + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_NAME + " TEXT,"
                + KEY_PH_NO + " TEXT" + ")";
        
        String CREATE_CONTACTS_TABLE2 = "CREATE TABLE " + TABLE_PASS + "("
                + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_NAME + " TEXT,"
                + KEY_PH_NO + " TEXT" + ")";
        db.execSQL(CREATE_CONTACTS_TABLE);
        db.execSQL(CREATE_CONTACTS_TABLE2);
    }
 

Ähnliche Themen

A
Antworten
1
Aufrufe
634
swa00
swa00
Manny87
  • Manny87
Antworten
11
Aufrufe
161
swa00
swa00
R
  • raller
Antworten
15
Aufrufe
544
DOT2010
DOT2010
Zurück
Oben Unten