2012-03-18 129 views
1

你好,任何幫助將是偉大的謝謝你! 我有3場在我的數據庫表返回整數數組的SQLite查詢數據

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; 
    } 

我不知道我錯過了什麼謝謝!

+1

我也不清楚,你錯過了什麼,因爲你沒有指定什麼是你所要完成的,你是如何在不及格的。 – SWeko 2012-03-18 10:04:23

回答

3

您正在比較字符串與==不正確。使用equals

if(c.getString(iExpense).equals("House")) 
    . 
    . 
    . 
+0

公共無效的onCreate(SQLiteDatabase分貝){ \t \t \t // TODO自動生成方法存根 \t \t \t db.execSQL( 「創建表」 + IncomeTable + 「(」 + colID + 「整數PRIMARY KEY AUTOINCREMENT,」 + colIncome +「money);」); db.execSQL(「create table」+ ExpenseTable +「(」+ colExpID +「Integer PRIMARY KEY AUTOINCREMENT,」+ colExpExpense +「text,」+ colExpAmount +「money);」); \t \t \t \t \t} – user996502 2012-03-18 19:36:26

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);"); 

     }