I have been working on some sqlite database and i have created one table,and have successfully inserted data,How to fetch the data and display in a textview?
public class EmployeeTable{
public static final String KEY_NAME = "emp_name";
public static final String KEY_DESIGNATION = "emp_designation";
public static final String KEY_ROWID = "_id";
private static final String TAG = "EmployeeTable";
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;
private static final String DATABASE_NAME = "employee_database";
private static final String DATABASE_TABLE = "employee";
private static final int DATABASE_VERSION = 3;
/**
* Database creation sql statement
*/
private static final String DATABASE_CREATE =
"create table " + DATABASE_TABLE + " (" + KEY_ROWID + " integer primary key autoincrement, "
+ KEY_NAME +" text not null, " + KEY_DESIGNATION + " text not null);";
private final Context mCtx;
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.i(TAG, "Creating DataBase: " + DATABASE_CREATE);
db.execSQL(DATABASE_CREATE);
}`
following in my main class:
public class SqliteDBActivity extends Activity {
/** Called when the activity is first created. */
private static final String TAG = "EmployeeTable";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EmployeeTable employeeTable = new EmployeeTable(this);
employeeTable.open();
employeeTable.createEmployee("Prashant Thakkar", "Tech Lead");
employeeTable.createEmployee("Pranay anand", "Tech Lead");
employeeTable.createEmployee("rajeev kumar", "Tech Lead");
Log.i(TAG, "Fetching record...");
employeeTable.close();
}
}