我在Android工作室有一个应用程序,我从外部数据库中获取一些数据。所以我想在某些情况下获取特定数据,我在我的databaseHelper中使用了一个if语句实际上对我不起作用。您可以在公共列表getListMbs()中看到if语句。当我打开应用程序时,它实际上只是从表中获取所有内容,因此if不起作用。
public class DatabaseHelper extends SQLiteOpenHelper{
public static final String DBNAME = "mydb.sqlite";
public static final String DBLOCATION = "/data/data/com.hfad.myapp/databases/";
private Context mContext;
private SQLiteDatabase mDatabase;
public DatabaseHelper(Context context) {
super(context, DBNAME, null, 1);
this.mContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public void openDatabase() {
String dbPath = mContext.getDatabasePath(DBNAME).getPath();
if(mDatabase != null && mDatabase.isOpen()) {
return;
}
mDatabase = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
}
public void closeDatabase() {
if(mDatabase!=null) {
mDatabase.close();
}
}
public List<Cases> getListCases() {
Cases caze= null;
List<Cases> casesList = new ArrayList<>();
openDatabase();
Cursor cursor = mDatabase.rawQuery("SELECT * FROM Cases", null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
caze = new Cases(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), ListCases.pose);
casesList.add(caze);
cursor.moveToNext();
}
cursor.close();
closeDatabase();
return casesList;
}
public List<Motherboards> getListMbs() {
Motherboards mbs = null;
List<Motherboards> mbsList = new ArrayList<>();
openDatabase();
String query = ("SELECT * FROM Motherboards");
if(ListCases.mboardsize == "mATX"){
query="SELECT * FROM Motherboards WHERE Size ='mATX'";
}
if(ListCases.mboardsize == "ATX")
{
query="SELECT * FROM Motherboards WHERE Size ='ATX'";
}
Cursor cursor = mDatabase.rawQuery(query, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
mbs = new Motherboards(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), mainmenu.motherboard_btn_state);
mbsList.add(mbs);
cursor.moveToNext();
}
cursor.close();
closeDatabase();
return mbsList;
}
}
答案 0 :(得分:0)
错误比较
==
- &GT;
.equals("string");