0

The code to returns all the data in the table in list.But this isn't working. I've called this method from CheckData class which is called by main class

public List<String[]> selectAll() {
        List<String[]> list = new ArrayList<String[]>();
        Cursor cursor = db
                .query(TABLE_NAME, null, null, null, null, null, null);
        int x = 0;
        if (cursor.moveToFirst()) {
            do {
                String[] b1 = new String[] { cursor.getString(1),
                        cursor.getString(2) };
                list.add(b1);
                x = x + 1;
            } while (cursor.moveToNext());
        }
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
        cursor.close();
        return list;
    }

My database contains 3 columns - id(integer primary key), symbol(text) and company_name(text).

My Data Base name is AppDB and table name is scrip.

10
  • What is it that isn't working? What do you see? Commented Nov 23, 2011 at 12:23
  • First Explain what you want to ask... Commented Nov 23, 2011 at 12:29
  • @zmbq - When I run the app, first i see a button then i click on it. Commented Nov 23, 2011 at 12:40
  • it should display all data from database, but instead it shows that application has stopped working. Commented Nov 23, 2011 at 12:40
  • MY BASIC PURPOSE IS TO DISPLAY DATA ON ANDROID EMULATOR WHICH IS STORED IN AN ALREADY CREATED SQLITE DATABASE. WHAT CAN I DO? Commented Nov 23, 2011 at 12:42

1 Answer 1

1

Here are the good tutorial to LEARN use of Android-SQLite. so,I also advise you the same As I answered here

Sign up to request clarification or add additional context in comments.

4 Comments

But all these tutorials shows demo in which we create database and table during coding. I already have the database. I have to fetch the data.
buddy, it's not like that. The thing is after modifying the code so that it displays the data from existing database, it doesn't work.
Now code contains (1) list.get(x); Log.e("selectAll method Error", b1[x]); x = x + 1; and(2) Cursor cursor = db.rawQuery( "select symbol,company_name from Scrip", new String[] { "symbol", "company_name" });
i just seen one another question stackoverflow.com/questions/4842520/… just check

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.