Reading integers from SQLite database returns 0?

Course Queries Syllabus Queries 3 years ago

3.66K 1 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago


In my Android application, I have an SQLite database that stores a students grade information. I am able to read in the category of the grade correctly but for some reason when i try to read in the grade itself resCurs.getInt(gradeIndex) returns 0 every time even though the grade value in my database is clearly not 0. Any help would be greatly appreciated as I see nothing wrong with my code

GradeDBOpenHelper.java

package bcs421.jorgeramirez.hwk.gradeapp.adv;

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

 public class GradeDBOpenHelper extends SQLiteOpenHelper {

public static final String DATABASE_NAME = "GradeData.db";
public static final String DATABASE_TABLE = "GradeData";
public static final int DATABASE_VERSION = 1;

public static final String KEY_ID = "_id";
public static final String COLUMN_CAT = "category";
public static final String COLUMN_NUM = "itemnumber";
public static final String COLUMN_DESC = "description";
public static final String COLUMN_GRD = "grade";
public static final String COLUMN_DATE = "date";

static final String DATABASE_CREATE =
        "CREATE TABLE " + DATABASE_TABLE +  "(" + 
        KEY_ID + " integer primary key autoincrement, " +
        COLUMN_CAT + " varchar(20), " +
        COLUMN_NUM + " integer, " +
        COLUMN_DESC + " varchar(255), " +
        COLUMN_GRD + " integer, " +
        COLUMN_DATE + " varchar(255));";

private static final String STUDENT_SELECT =
        "SELECT * FROM " + DATABASE_TABLE + ";";

static final String GRADE_INSERT_1 =
        "INSERT INTO " + DATABASE_TABLE + " VALUES (NULL, 'Homework', 1, 'Assigment 1 - Schedule App', 100, '02/10/2015');";

static final String GRADE_INSERT_2 =
        "INSERT INTO " + DATABASE_TABLE + " VALUES (NULL, 'Quiz', 1, 'Quiz - Syllabus', 100, '02/10/2015');";

static final String GRADE_INSERT_3 =
        "INSERT INTO " + DATABASE_TABLE + " VALUES (NULL, 'Lab', 1, 'Lab Ch1 - Hello Yankees', 100, '01/28/2015');";

static final String GRADE_INSERT_4 =
        "INSERT INTO " + DATABASE_TABLE + " VALUES (NULL, 'Lab', 2, 'Lab - Hello World', 100, '02/04/2015');";

static final String GRADE_INSERT_5 =
        "INSERT INTO " + DATABASE_TABLE + " VALUES (NULL, 'Lab', 3, 'Lab - Manifest and Different Screens', 0, '02/09/2015');";







public GradeDBOpenHelper(Context context, String name, CursorFactory factory, int version) {
    super(context, name, factory, version);

}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(DATABASE_CREATE);
    db.execSQL(GRADE_INSERT_1);
    db.execSQL(GRADE_INSERT_2);
    db.execSQL(GRADE_INSERT_3);
    db
                                                
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum