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 8319441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:19:44+00:00 2026-06-08T22:19:44+00:00

I am having trouble with storing integer value in SQLite database. Here are my

  • 0

I am having trouble with storing integer value in SQLite database.
Here are my codes.

My insert code of the Create_Events.java

Button btnCreate = (Button)findViewById(R.id.saveButton);
btnCreate.setOnClickListener(new OnClickListener()
{

        @Override
        public void onClick(View v)
        {
           calDB.open();
           long _id;
           EditText txtTitle = (EditText) findViewById(R.id.txtTitle);
          String title = txtTitle.getText().toString(); 
           EditText txtLocation = (EditText) findViewById(R.id.editText1);
           String location = txtLocation.getText().toString();
           EditText startTime = (EditText) findViewById(R.id.editText2);
           String startTime = startTime.getText().toString();
          _id = calDB.insertEvent(title, location, 0, 0);

           calDB.close();

        }

});

CalendarAdapter.java (Database class)

package main.page;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class CalendarAdapter
{
    public static final String KEY_ROWID = "_id";
    public static final String KEY_TITLE = "title";
    public static final String KEY_LOCATION = "location";
    public static final String KEY_START = "starttime";
    public static final String KEY_END = "endtime";
    private static final String TAG = "DBAdapter";

    private static final String DATABASE_NAME = "anniversary";
    private static final String DATABASE_TABLE = "calendar";
    private static final int DATABASE_VERSION = 2;

    private static final String DATABASE_CREATE = "create table calendar(_id integer primary key autoincrement,"+
    "title text not null, location text not null, starttime integer, endtime integer);";

    private final Context context;

    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;


    public CalendarAdapter(Context ctx)
    {
        this.context = ctx;
        DBHelper = new DatabaseHelper(context);
    }

    private static class DatabaseHelper extends SQLiteOpenHelper
    {
        DatabaseHelper(Context context)
        {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db)
        {
            try
            {
            db.execSQL(DATABASE_CREATE);    
            }catch(SQLException e)
            {
                e.printStackTrace();
            }

        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
        {
            Log.w(TAG, "Upgrading database from version "+oldVersion+" to "+newVersion+", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS calendar");
            onCreate(db);
        }

    }

    public CalendarAdapter open() throws SQLException
    {
        db = DBHelper.getWritableDatabase();
        return this;
    }

    public void close()
    {
        DBHelper.close();
    }

    public long insertEvent(String title, String location, int starttime, int endtime)
    {
       ContentValues initialValues = new ContentValues();
       initialValues.put(KEY_TITLE, title);
       initialValues.put(KEY_LOCATION, location);
       initialValues.put(KEY_START, starttime);
       initialValues.put(KEY_END, endtime);
       return db.insert(DATABASE_TABLE, null, initialValues);

    }

    public boolean deleteEvent(long rowId)
    {
        return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
    }

    public Cursor getAllEvents()
    {
        return db.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE, KEY_LOCATION, KEY_START, KEY_END}, null, null, null, null, null);

    }

    public Cursor getEvent(long rowId) throws SQLException
    {
        Cursor c = db.query(true, DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE, KEY_LOCATION, KEY_START, KEY_END}, KEY_ROWID + "=" + rowId, null, null, null, null, null);
        if(c != null)
        {
            c.moveToFirst();
        }
        return c;
    }

    public boolean updateEvent(long rowId, String title, String location, int starttime, int endtime)
    {
        ContentValues args = new ContentValues();
        args.put(KEY_TITLE, title);
        args.put(KEY_LOCATION, location);
        args.put(KEY_START, starttime);
        args.put(KEY_END, endtime);
        return db.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;

    }

}

As you can see above, I have managed to store text values from the EditText into the database successfully. So now I am trying to store the starttime(Integer) into database.
Any help will be greatly appreciated. Thanks a bunch!

  • 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-06-08T22:19:46+00:00Added an answer on June 8, 2026 at 10:19 pm

    I guess your real Question is “How to store a TIME or DATE in the SQLite database”?
    You need to convert those into integer to store them, and convert back to whatever you for reading.
    Please check chapter 1.2 of the SQLite documentation on that topic: http://www.sqlite.org/datatype3.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble storing and retrieving a float in NSUserDefauts. I store the value,
I'm having trouble getting data from a ResultSet object. Here is my code: String
I having trouble storing objects in an ArrayList . I want to populate an
I am having trouble storing a numpy csr_matrix with PyTables. I'm getting this error:
I'm having trouble looping through a set of dynamically created UITextFields and storing those
I'm having some trouble with the logic behind storing an ImageView into an ArrayList.
I am having a little trouble designing an efficient data storage method of storing
I am having trouble converting a value in a string array to int since
I am having trouble sending JSON to a WebMethod. Here is the way that
I'm having trouble getting any sense back from my mySQL database. I'm passing it

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.