Reading integers from SQLite database returns 0?

Course Queries Syllabus Queries 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 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.