1

Hello any help would be great thank you! i have 3 fields in my database table

public static final String colExpID = "ExpenseID";      
public static final String colExpExpense = "ExpenseDisc";
public static final String colExpAmount = "Amount";

My method to query data

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

I'm not sure what i'm missing thank you!

1
  • 1
    I'm also not sure what you missing, since you have not specified what it is you are trying to accomplish, and how you are failing at that. Commented Mar 18, 2012 at 10:04

2 Answers 2

3

You are comparing string with == which is NOT correct. use equals :

  if(c.getString(iExpense).equals("House")) 
    .
    .
    .
Sign up to request clarification or add additional context in comments.

1 Comment

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

        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.