Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6037349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:03:36+00:00 2026-05-23T06:03:36+00:00

I am trying to put together an SQL database but don’t really know how

  • 0

I am trying to put together an SQL database but don’t really know how to make it work. The intention is to have multiple columns, some with integers, some with strings in their cells. For this app, I want repetitions to be an integer and exercise to be a string. Here is the relevant parts of the code:

public static final String KEY_ROWID = "_id";
public static final String KEY_DATE = "date";
public static final String KEY_EXERCISE = "exercise";
public static final String KEY_REPS = "repetitions";

private static final String DATABASE_CREATE = "create table " + DATABASE_TABLE + " (" 
    + KEY_ROWID + " integer primary key autoincrement, "
    + KEY_DATE + " text not null, " 
    + KEY_EXERCISE + " text not null, "
    + KEY_REPS + " int not null, "

public long createExercise(String exercise, int reps) {
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_DATE, date);
    initialValues.put(KEY_EXERCISE, exercise);
    initialValues.put(KEY_REPS, reps);

return mDb.insert(DATABASE_TABLE, null, initialValues);
}

I put data in this table using test strings. Then I try to pull the data with the following query:

public Cursor graphQuery(String exercise, String workout) {
    return mDb.query(DATABASE_TABLE, new String[] {KEY_DATE, KEY_REPS}, null, null,    
        null, null, null);

From there I try to put the data into a number array but it gives me an error. It tells me to put KEY_REPS as a number when I declared it. But if I declare KEY_REPS as a number it doesn’t let me build my databes.

Cursor cursor = mDbHelper.graphQuery(currentexercise, currentworkout);
startManagingCursor(cursor);
Number[] reps = new Number[]{workoutDbAdapter.KEY_REPS};  //error here

I feel like I am missing a key part in how to create my database. Can anyone help?

Code from book I am trying to follow (except using integers) (from comment on first answer)

private void fillData() {
    Cursor remindersCursor = mDbHelper.fetchAllReminders();
    startManagingCursor(remindersCursor);
// Create an array to specify the fields we want (only the TITLE)
    String[] from = new String[]{RemindersDbAdapter.KEY_TITLE};

That being said, if someone knows of a good website that teaches SQLite as it applies to Android that would be awesome. The only ones I have been able to find are generic SQL sites and they aren’t very helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:03:37+00:00Added an answer on May 23, 2026 at 6:03 am
    Cursor cursor = mDbHelper.graphQuery(currentexercise, currentworkout);
    startManagingCursor(cursor);
    Number[] reps = new Number[]{WorkoutDbAdapter.KEY_REPS};  //error here
    

    This code here doesn’t do what (I think) you want it to. You need to iterate over the cursor and get the data from there. I’m pretty sure, if you followed the Android sample code for using databases that WorkoutDbAdapter.KEY_REPS is a string constant that holds reps column name.

    Try doing something like this:

    List<Number> allReps = new ArrayList<Number>();
    Cursor cursor = mDbHelper.graphQuery(currentexercise, currentworkout);
    while (cursor.moveToNext()) {
        int reps = cursor.getInt(cursor.getColumnIndexOrThrow(mDbHelper.KEY_REPS));
        allReps.add(reps);
    }
    Number[] repsArray = allReps.toArray(new Number[]{});
    // do stuff with repsArray and don't forget to close cursor
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to put together a tool that will help me make work schedules.
I am trying to make some changes to an oracle database and have a
We're trying to put together kiosk solution where we can charge people by hour
I'm trying to put together a comprehensive regex to validate phone numbers. Ideally it
I am trying to put a requirement together for a new environment to consist
I am trying to put all the pieces together for my MVVM Silverlight application
I have a linq query and I am trying to put that in to
I am trying to put together a deployment package for a psolution which needs
I'm trying to put together a simple system for a user to generate a
I have put together a small ASP.NET MVC 2 site that does some very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.