mardi 19 mai 2015

SQLite within Android Application

I am currently trying to learn Java and therefore i started making an application to android, where i need SQLite, Everything seems to work fine, however i can't seem to get the update statement to work.

I got a .java file with all the SQLite statement that starts with:

public static final String KEY_ROWID = "_id";
public static final String KEY_TASK1 = "Content";
public static final String KEY_TASK2 = "Name";
public static final String KEY_TASK3 = "Stack";
public static final String DATABASE_NAME = "DBName";
public static final String DATABASE_TABLE = "Table";
public static final int DATABASE_VERSION = 10;

private static final String DATABASE_CREATE_SQL = 
        "CREATE TABLE " + DATABASE_TABLE 
        + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
        + KEY_TASK1 + " Varchar UNIQUE, "
        + KEY_TASK2 + " TEXT NOT NULL, "
        + KEY_TASK3 + " INTEGER"
        + ");";

and the update i call within my application:

public boolean updateRow(Integer task1, Integer task3) {
    String where = KEY_TASK1 + "=" + task1;
    ContentValues newValues = new ContentValues();
    newValues.put(KEY_TASK3, task3);
    // Insert it into the database.
    return db.update(DATABASE_TABLE, newValues, where, null) != 0;
}

And in my main .java file i call:

private void ScanOutItem (View view){
    myDb.updateRow("5741000124024", 2);
}

which i have binded to a button within my application. As i said in the beginning this is my first application i have made, so can't promise it's perfect. however if i'm missing something or you can see what's wrong, please do tell. feels like i have tried everything, any help is appreciated.

I have used a guide i saw on youtube, but i made some changes these according to the guide it wasn't fit for my app.

Guide: https://www.youtube.com/watch?v=9zEKKKEFtHQ

Aucun commentaire:

Enregistrer un commentaire