我是这些 sqlite 访问编程的新手。我有 9 个 edittext 并编码以将值存储在 sqlite db 中......下次如果我在第一个 edittext 中插入相同的值,剩余的值应该在不输入的情况下显示..下面的代码是我尝试过的但无法取回价值
//this is my dbhandler class method
> public Data findProduct(String phone) { String query = "Select *
> FROM " + TABLE_FEEDBACK + " WHERE " + COLUMN_PHONENO + " = \"" +
> phone + "\"";
> SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
Data data = new Data(); if (cursor.moveToFirst()) { cursor.moveToFirst(); data.setPHONE(cursor.getString(0)); data.setName(cursor.getString(1)); data.setFood(cursor.getString(2)); data.setService(cursor.getString(3)); data.setCleanliness(cursor.getString(4)); data.setExperience(cursor.getString(5)); data.setAddress(cursor.getString(6)); data.setEmail(cursor.getString(7)); data.setBirthday(cursor.getString(8)); data.setAnniversary(cursor.getString(9)); data.setFavrestaurant(cursor.getString(10)); data.setFavstaff(cursor.getString(11)); data.setFavdish(cursor.getString(12)); data.setSuggestion(cursor.getString(13)); data.setReturn(cursor.getString(14)); cursor.close(); } else { data = null; } db.close(); return data; }
/*public void openDataBase(SQLiteDatabase db) throws SQLException { //Open the database String myPath = DB_PATH + DATABASE_NAME; db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } */
//this is my mainactivity method
public void lookupProduct (View view) { DBHandler dbHandler = new DBHandler(MainActivity.this); Data data = dbHandler.findProduct(phonenumber.getText().toString()); if (data != null) { name.setText(String.valueOf(data.getName())); address.setText(String.valueOf(data.getAddress())); } else { name.setText("No Match Found"); } }