Thursday, March 19, 2015

All About Database Handler - Part 2

Now , We see how to use it..

1. get all data from TABLE_POINTS

DatabaseHandler db = new DatabaseHandler(this);

Cursor cursor = db.getAllPoints();

cursor.moveToFirst();
do {

int points = Integer.toString(cursor.getInt(0));
String dates = String.valueOf(cursor.getString(1));
types = String.valueOf(cursor.getString(2));
Log.i("counttttttttttttt", "" + cursor.getCount() + " points"
+ cursor.getInt(0) + " type" + cursor.getString(2));
} while (cursor.moveToNext());

db.close();
cursor.close();

2. add data to TABLE_DATA

DatabaseHandler db = new DatabaseHandler(
LoginActivity.this);
db.addData(name.trim(), username.getText().toString()
.trim(), pass.getText().toString().trim(),
dob.trim());

db.close();


You can use the format and syntax as you need.

No comments:

Post a Comment