Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Android SQLite.

  • 11-03-2013 01:35PM
    #1
    Registered Users, Registered Users 2 Posts: 3,512 ✭✭✭


    Hey, I am making an android app and this is first time I am required to use and learn SQLite.
    I was following some crap tutorial which lead me nowhere and I ended up having this file:
    package com.example.droid;

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

    public class SqDb extends SQLiteOpenHelper{
    private static final String NAME = SqDb.class.getSimpleName();

    public static final String dName = "ExpenseR.db";
    public static final int dVer = 1;
    public static final String table = "Expenses";
    public static final String sql = "create table user_data (" +
    "_id INT PRIMARY KEY AUTOINCREMENT, " +
    "_typ VARCHAR(20)," +
    "_desc VARCHAR(255)," +
    "_day INT(2)," +
    "_mon INT(2)," +
    "_cat VARCHAR(25)," +
    "_val REAL," +
    "_time TIMESTAMP);";

    public SqDb(Context context) {
    super(context, dName, null, dVer);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
    db.execSQL(sql);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }

    }

    How do I add/read entries from db from other classes.


Advertisement