Saturday, March 9, 2013
How to Retrieve Results From SQLite in Android
1. Open the Eclipse software and load your Android app project. In the left column, double-click the Java class file you want to use to query the SQLite database.
2. Create the SQLite connection and variable, and assign the connection to a Java variable. The following code shows you how to make a connection using an internal Android function:SQLiteDatabase database =this.getReadableDatabase();
3. Query the database. You can query any table or records. The following query retrieves a list of contacts:Cursor data =db.query('select name from contacts');
4. Move to the first record and retrieve the first contact name. The following code shows you how to retrieve individual records from the cursor object created in Step 3:data.moveToFirst();
string name = data.getString(data.getColumnIndex('name'))
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment