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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:43:38+00:00 2026-05-31T06:43:38+00:00

Can anyone alter this code to include one integer variable. Not including the database

  • 0

Can anyone alter this code to include one integer variable. Not including the database version integer of course. 🙂

package T2T.Game;

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 DatabaseUtil {

 private static final String TAG = "DatabaseUtil";  



 /**  

  * Database Name  

  */ 

 private static final String DATABASE_NAME = "t2tvariables_database";  



 /**  

  * Database Version  

  */ 

 private static final int DATABASE_VERSION = 1;  



 /**  

  * Table Name  

  */ 

 private static final String DATABASE_TABLE = "tb_variable";  



 /**  

  * Table columns  

  */ 

 public static final String KEY_VARIABLE = "variable";  

 public static final String KEY_VALUE = "grade";  

 public static final String KEY_ROWID = "_id";  


 /**  

  * Database creation sql statement  

  */ 

 private static final String CREATE_VARIABLE_TABLE =  

     "create table " + DATABASE_TABLE + " (" + KEY_ROWID + " integer primary key autoincrement, " 

     + KEY_VARIABLE +" text not null, " + KEY_VALUE + " text not null);";  



 /**  

  * Context  

  */ 

 private final Context mCtx;  



 private DatabaseHelper mDbHelper;  

 private SQLiteDatabase mDb;  



 /**  

  * Inner private class. Database Helper class for creating and updating database.  

  */ 

 private static class DatabaseHelper extends SQLiteOpenHelper {  
     DatabaseHelper(Context context) {  

         super(context, DATABASE_NAME, null, DATABASE_VERSION);  

     }  

     /**  

      * onCreate method is called for the 1st time when database doesn't exists.  

      */ 

     @Override 

     public void onCreate(SQLiteDatabase db) {  

         Log.i(TAG, "Creating DataBase: " + CREATE_VARIABLE_TABLE);  

         db.execSQL(CREATE_VARIABLE_TABLE);  

     }  

     /**  

      * onUpgrade method is called when database version changes.  

      */ 

     @Override 

     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {  

         Log.w(TAG, "Upgrading database from version " + oldVersion + " to " 

                 + newVersion);  

     }  

 }  



 /**  

  * Constructor - takes the context to allow the database to be  

  * opened/created  

  *  

  * @param ctx the Context within which to work  

  */ 

 public DatabaseUtil(Context ctx) {  

     this.mCtx = ctx;  

 }  

 /**  

  * This method is used for creating/opening connection  

  * @return instance of DatabaseUtil  

  * @throws SQLException  

  */ 

 public DatabaseUtil open() throws SQLException {  

     mDbHelper = new DatabaseHelper(mCtx);  

     mDb = mDbHelper.getWritableDatabase();  

     return this;  

 }  

 /**  

  * This method is used for closing the connection.  

  */ 

 public void close() {  

     mDbHelper.close();  

 }  



 /**  

  * This method is used to create/insert new record Variable record.  

  * @param variable  

  * @param integer  

  * @return long  

  */ 

 public long createVariable(String variable, String grade ) {  

     ContentValues initialValues = new ContentValues();  

     initialValues.put(KEY_VARIABLE, variable);  

     initialValues.put(KEY_VALUE, grade);


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

 }  

 /**  

  * This method will delete Variable record.  

  * @param rowId  

  * @return boolean  

  */ 

 public boolean deleteVariable(long rowId) {  

     return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;  

 }  



 /**  

  * This method will return Cursor holding all the Variable records.  

  * @return Cursor  

  */ 

 public Cursor fetchAllVariables() {  

     return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_VARIABLE,  

             KEY_VALUE}, null, null, null, null, null);  

 }  


 /**  
  * This method will return Cursor holding the specific Variable record.  

  * @param id  

  * @return Cursor  

  * @throws SQLException  

  */ 

 public Cursor fetchVariable(long id) throws SQLException {  

     Cursor mCursor =  

         mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,  

                 KEY_VARIABLE, KEY_VALUE}, KEY_ROWID + "=" + id, null,  

                 null, null, null, null);  

     if (mCursor != null) {  

         mCursor.moveToFirst();  

     }  

     return mCursor;  

 }  



 /**  

  * This method will update Variable record.  

  * @param id  

  * @param variable  

  * @param standard  

  * @return boolean  

  */ 

 public boolean updateVariable(int id, String variable, String standard) {  

     ContentValues args = new ContentValues();  

     args.put(KEY_VARIABLE, variable);  

     args.put(KEY_VALUE, standard);


     return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + id, null) > 0;







 }  

}

  • 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-31T06:43:40+00:00Added an answer on May 31, 2026 at 6:43 am

    You can put any type of value into any type of column in sqlite databse.. except that if you try to put anything other than an integer into an INTEGER PRIMARY KEY column you get an error.. so you should not have any problem inserting integers into database… while you are retrieving the values.. you can type cast them into required type.. as integers in this case…

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

Sidebar

Related Questions

Can anyone tell me why I always have this strange output after running this
Can anyone tell me where is the mistake in the following query ALTER TABLE
Can anyone tell me how to write javascript code that removes everything after the
I have a string which can include none, one or two values. In case
Can anyone recommend any tools for compile and runtime analysis of C++ code? I'm
I am trying to implement a generic version of the code below: #include <iostream>
Can anyone confirm that after changing the Apple Push Certificate to follow the new
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can anyone tell me how I can display a status message like 12 seconds
Can anyone recommend a good library for generating an audio file, such as mp3,

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.