您好任何帮助都会非常感谢! 我的数据库表中有3个字段
public static final String colExpID = "ExpenseID";
public static final String colExpExpense = "ExpenseDisc";
public static final String colExpAmount = "Amount";
我查询数据的方法
public Integer[] queryHouse() {
// TODO Auto-generated method stub
String[] columns = new String[]{colExpID,colExpExpense,colExpAmount};
Integer[] Result = new Integer[]{};
Cursor c = ourDatabase.query(ExpenseTable, columns, null, null, null, null, null);
int iExpense = c.getColumnIndex(colExpExpense);
int iAmount = c.getColumnIndex(colExpAmount);
for(int i = 0; i < c.getCount();i++){
if(c.getString(iExpense) == "House"){
Result[i] = Integer.parseInt(c.getString(iAmount));
}
}
return Result;
}
我不确定我错过了什么,谢谢!
答案 0 :(得分:3)
您正在将字符串与==进行比较,这是不正确的。使用equals
:
if(c.getString(iExpense).equals("House"))
.
.
.
答案 1 :(得分:0)
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("create table " + IncomeTable + " (" + colID + " Integer PRIMARY KEY AUTOINCREMENT, " + colIncome + " money);");
db.execSQL("create table " + ExpenseTable + " (" + colExpID + " Integer PRIMARY KEY AUTOINCREMENT, " + colExpExpense + " text, " + colExpAmount + " money);");
}