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

  • SEARCH
  • Home
  • 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 8593157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:55:29+00:00 2026-06-11T23:55:29+00:00

In my app I have a dbhelper class where everything in my database happens,

  • 0

In my app I have a dbhelper class where everything in my database happens, I know I have to use the onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) but I’m having problems on understanding how do I call it if I’m not updating the complete application, all I want is that in the internet call finds that I have change the version in my web table to drop tables in my app and rebuild them so it could get the new information.
Here is my code:

In my bd helper:

public class CuestionarioHelper extends SQLiteOpenHelper {

private static String DB_PATH = "/data/data/myapp.VerCuestionarioEspanol_copy/databases/";
private static final String DB_NAME="cuestionario.db";
private static final int SCHEMA_VERSION=1;
private SQLiteDatabase myData; 
public CuestionarioHelper(Context context) {
    super(context, DB_NAME, null, SCHEMA_VERSION);
}   
@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE Version (_id INTEGER PRIMARY KEY AUTOINCREMENT, version TEXT);");
    db.execSQL("CREATE TABLE Cuestionario (_id INTEGER PRIMARY KEY AUTOINCREMENT, pregunta TEXT, respuesta TEXT);");
    }
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + "Version");
    db.execSQL("DROP TABLE IF EXISTS " + "Cuestionario");
    onCreate(db);
}

and in my mainActivity:

private CuestionarioHelper db = null;

 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

   db = new CuestionarioHelper(this);

// here in a  class DownloadFileAsync extends AsyncTask<String, String, String> 
  I download the version of the table in the web and if is different than the one 
  already in the db then it calls the table complete information to replace the one 
  in the apps db.

//Here I verify what table version I have so I can add to a non existing table, 
  do nothing if both versions are the same or replace the bd table if they are different.

public void verficar(){

verify = db.getTableCount();
if(verify == 0){
    tvVersion.setText("Version nueva "+Version.get(0).version);
    // download the table information and added to the db
}else{
    if(versionEntrada.equals(db.getVersion())){
        tvVersion.setText("Version ya existe "+db.getVersion());
           //version is the same do nothing
    }else{
        int oldVersion = Integer.parseInt(db.getVersion());
        int newVersion = Integer.parseInt(versionEntrada);
        db.onUpgrade(db, oldVersion, newVersion);//here is where I don't know 
                                                    //how to call it, this is not working!
        // download the table information and added to the db
        tvVersion.setText("Version actualizada "+Version.get(0).version);
    }
}
}

In the db the Version table is where I store the table version or it could be the db version it only has one column and one row since it will be just one number to compare to my web table version.

  • 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-11T23:55:30+00:00Added an answer on June 11, 2026 at 11:55 pm

    You should make your SCHEMA_VERSION not final and pass this version as a parameter:

    change these lines

    private static final int SCHEMA_VERSION=1;
    public CuestionarioHelper(Context context) {
        super(context, DB_NAME, null, SCHEMA_VERSION);
    }   
    

    to (notice that SCHEMA_VERSION is removed)

    public CuestionarioHelper(Context context, int version) {
        super(context, DB_NAME, null, version);
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using an sqlite database in my app. I have this dbhelper class in
Ok this is going to sound strange, but I have inherited an app that
I have a small problem. My app has a database which stores lazy loaded
I have the following DB helper class: public int studentExists(String studid) { Cursor dataCount
i need to use Base64 on my app (import android.util.Base64;) but Base64 was included
I have an app that uses an sqlite database. Currently I have a database
I have an Android app where I've extended the base Application class in order
I have three class in my app. First extends Activity public class TestProjActivity extends
I have an app that must open a sqlitedatabase from a .db file on
I'm building an Android app, and have set up a base DBObject class to

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.