Code: Part1

package org.meicode.meibank;


import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;

import org.meicode.meibank.Database.DatabaseHelper;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = “MainActivity”;

    protected void onCreate(Bundle savedInstanceState) {

        DatabaseHelper databaseHelper = new DatabaseHelper(this);
        SQLiteDatabase db = databaseHelper.getReadableDatabase();
        Cursor cursor = db.query(“items”, null, null, null, null, null, null);
        if (null != cursor) {
            if (cursor.moveToFirst()) {
                Log.d(TAG, “onCreate: name: ” + cursor.getString(cursor.getColumnIndex(“name”)));

package org.meicode.meibank.Database;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

public class DatabaseHelper extends SQLiteOpenHelper {
    private static final String TAG = “DatabaseHelper”;

    private static final String DB_NAME = “fb_mei_bank”;
    private static final int DB_VERSION = 1;

    public DatabaseHelper(@Nullable Context context) {
        super(context, DB_NAME, null, DB_VERSION);

    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        Log.d(TAG, “onCreate: started”);
        String createUserTable = “CREATE TABLE users (_id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT NOT NULL, ” +
                “password TEXT NOT NULL, ” +
                “first_name TEXT, last_name TEXT, address TEXT, image_url TEXT, remained_amount DOUBLE)”;

        String createShoppingTable = “CREATE TABLE shopping (_id INTEGER PRIMARY KEY AUTOINCREMENT, item_id INTEGER, ” +
                “user_id INTEGER, transaction_id INTEGER, price DOUBLE, date DATE, description TEXT)”;

        String createInvestmentTable = “CREATE TABLE investments (_id INTEGER PRIMARY KEY AUTOINCREMENT, amount DOUBLE, ” +
                “monthly_roi DOUBLE, name TEXT, init_date DATE, finish_date DATE, user_id INTEGER, transaction_id INTEGER)”;

        String createLoansTable  = “CREATE TABLE loans (_id INTEGER PRIMARY KEY AUTOINCREMENT, init_date DATE, ” +
                “finish_date DATE, init_amount DOUBLE, remained_amount DOUBLE, monthly_payment DOUBLE, monthly_roi DOUBLE,” +
                “name TEXT, user_id INTEGER)”;

        String createTransactionTable = “CREATE TABLE transactions (_id INTEGER PRIMARY KEY AUTOINCREMENT, amount double, ” +
                “date DATE, type TEXT, user_id INTEGER, recipient TEXT, description TEXT)”;

        String createItemsTable = “CREATE TABLE items (_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, image_url TEXT,” +
                “description TEXT)”;



    private void addInitialItems (SQLiteDatabase db) {
        Log.d(TAG, “addInitialItems: started”);
        ContentValues values = new ContentValues();
        values.put(“name”, “Bike”);
        values.put(“image_url”, “”);
        values.put(“description”, “The perfect mountain bike”);

        db.insert(“items”, null, values);

    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {


Subscribe To Our Newsletter
Get updates and learn from the best

Leave a Reply

Your email address will not be published. Required fields are marked *

Andriod Course

Table of Contents