Neha
Neha

Reputation: 255

how to get values of tables from existing database in android

I know how to call existing database but how should i get to know, how many tables in database and how to call tables in android programmatically.

Upvotes: 0

Views: 345

Answers (2)

Joe
Joe

Reputation: 2243

SELECT * from SQLITE_SEQUENCE;

I never tried it but I guess it should work .. theres always a sqlite_sequence table added automatically to the sqlite DB that lists all of your tables.

Upvotes: 1

user1203673
user1203673

Reputation: 1015

using cursor object you can call the database

inserting By Below method

public long insertinto(String a1, String a2, String a3,
         long a4) {
    // TODO Auto-generated method stub
    DBHelper.onOpen(db);
    ContentValues initialValues = new ContentValues();
    // initialValues.put(KEY_ROWID, _id);
    initialValues.put("aa", a1);
    initialValues.put("a2", a2);
    initialValues.put("a3", a3);        
    initialValues.put("a4", a4);

    return db.insert(DATABASE_Tab,leName, null, initialValues);

}

And for get Counting

public int getcount() {
        DBHelper.onOpen(db);
        SQLiteStatement i;
        i = db.compileStatement("select count(*) from " + DATABASE_TableName + ";");
        int count = (int) i.simpleQueryForLong();
        DBHelper.close();
        return count;

    }

Getting values

public Cursor fetchSecurityQuesAns(String username){
        DBHelper.onOpen(db);
        Cursor fetchSecurityQuesAns = db.query(TableName,
                new String[] {"S1","s2",
                "s3","s4"},  "Username=" + "'" + username+ "'", null, null, null, null);
        return fetchSecurityQuesAns;

    }

And call these methods where ever required

And follow the links

http://www.vogella.de/articles/AndroidSQLite/article.html

Upvotes: 0

Related Questions