我在类中创建了一个表,然后从数据库中的另一个类中插入值。 然后我尝试选择我插入的所有数据,但没有显示任何内容。我的insert或select语句必定是错误的。我希望你能帮助我: - )
//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());
}
答案 0 :(得分:0)
您需要FROM
和表名之间的空格:
String query = "SELECT * FROM " + TABLE_Aerzte + ";";
^