samedi 28 novembre 2015

Android Studio - sqlite insert does not work

I created a table in an class and I insert the values from another class in the database. I then try to select all the data I inserted, but nothing is shown. Either my insert or my select statement must be wrong. I hope you can help me :-)

//insert
  public void registerPhysician(String etname, String etpass) {

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(COLUMN_Name, etname);
    values.put(COLUMN_Passwort, etpass);
    //db.insert(TABLE_Aerzte, null, values);
    db.insert(TABLE_Aerzte, null, values);
    db.close();
}
 //select
   public void patlist(TextView patliste) {
    SQLiteDatabase db = getReadableDatabase();
    String query = "SELECT * FROM" + TABLE_Aerzte + ";";
}


 //my database:
  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";

  @Override
public void onCreate(SQLiteDatabase db) {
    String query = "CREATE TABLE  "+TABLE_Aerzte+"("+COLUMN_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+COLUMN_Passwort+" TEXT "+ COLUMN_Name+" TEXT )";
    db.execSQL(query);
     }

   //this is the other class from where I get the values from:
    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);
    init();
    mDb = new MyDBHandler(this,null,null,1);
    mDb.registerPhysician(etname.getText().toString(),etpass.getText().toString());
}

Aucun commentaire:

Enregistrer un commentaire