lundi 30 novembre 2015

Android: table has no column named 'columnname'

I have en error: android.database.sqlite.SQLiteException: table aerzte has no column named _vorname

But my table has the column _vorname. I can not find the error, please help me. Here is the code:

private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "data.db"; 
private static final String TABLE_Aerzte = "aerzte";
private static final String COLUMN_ID = "_id";
private static final String COLUMN_Name = "_name";
private static final String COLUMN_Passwort = "_passwort";
private static final String COLUMN_Vorname = "_vorname";

//second table
private static final String TABLE_Patienten = "patienten";
private static final String COLUMN_patID = "_id";
private static final String COLUMN_patName = "_name";
private static final String COLUMN_patVorname = "_vorname";
private static final String COLUMN_patSVNR = "_svnr";



//third table
private static final String TABLE_Werte = "werte";
private static final String COLUMN_wertID = "_id";
private static final String COLUMN_wertpatName = "_name"; //foreign key -> patient (1:n) beziehung
private static final String COLUMN_wertDatzeit = "_datzeit";
private static final String COLUMN_wertTemperatur = "_temperatur";
private static final String COLUMN_wertMessort = "_messort";

 public MyDBHandler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
    super(context, DATABASE_NAME, factory, DATABASE_VERSION);
     }


   //create tables:
       @Override
public void onCreate(SQLiteDatabase db) {
    //tabelle arzt
    String query = "CREATE TABLE  "+TABLE_Aerzte+"("+COLUMN_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+COLUMN_Passwort+" TEXT, "+COLUMN_Name+ " TEXT, " +COLUMN_Vorname+ "TEXT " + ");";
    db.execSQL(query);

    //tabelle patient
    String query2 = "CREATE TABLE  "+TABLE_Patienten+"("+COLUMN_patID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+COLUMN_patName+" TEXT,"+COLUMN_patVorname+" TEXT, "+COLUMN_patSVNR+" LONG" + ");";
    db.execSQL(query2);

    //tabelle wert
    String query3 = "CREATE TABLE  "+TABLE_Werte+"("+COLUMN_wertID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+COLUMN_wertMessort+" TEXT, "+COLUMN_wertTemperatur+ " INTEGER, "+COLUMN_wertDatzeit+" DATETIME, "+COLUMN_wertpatName+" TEXT, FOREIGN KEY" + ");";
    db.execSQL(query3);

}



//insert
 public void registerPhysician(Fieberwerte fieberwerte) { // public void registerPhysician(etname, etpass, etvorname)

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    //values.put(COLUMN_ID, 1);
    values.put(COLUMN_Passwort, fieberwerte.getPasswort());
    values.put(COLUMN_Name, fieberwerte.getName());
    values.put(COLUMN_Vorname, fieberwerte.getVorname());
    //db.insert(TABLE_Aerzte, null, values);
    db.insertWithOnConflict(TABLE_Aerzte, null, values, SQLiteDatabase.CONFLICT_REPLACE);
    //db.close();
}

I hope you guys can help me to fix this error. I checked the code several times but I do not find any error :-(

Aucun commentaire:

Enregistrer un commentaire