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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:31:18+00:00 2026-06-02T14:31:18+00:00

I can create the database just fine, I can Insert and view the values,

  • 0

I can create the database just fine, I can Insert and view the values, but whenever I close the android virtual device in eclipse and reopen it, the database values are gone! :O
Please help me!

There are 3 classes : (1 that handles the database and 2 activities)

It would mean the world to me!!! :O
I’d +rep if I coudl
Thank you guys sooo much!@!!!

Here is my code

Database manager :`

package com.jeux;

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;


public class Database2 {

private static final String DATABASE_NAME = "JeuxMotActivity";

private static final int DATABASE_VERSION = 1;

public static final String TABLE_CATEGORIE = "Categorie";
public static final String KEY_CATEGORIE_ID_CATEGORIE = "IDCategorie";
public static final String KEY_CATEGORIE_NOM_CATEGORIE = "NomCategorie";

public static final String TABLE_MOT = "Mot";
public static final String KEY_MOT_ID_MOT = "IDMot";
public static final String KEY_MOT_MOT = "Mot";
public static final String KEY_MOT_EMAIL = "Email";
public static final String KEY_MOT_ID_CATEGORIE = "IDCategorie";

public static final String TABLE_ADMINISTRATEUR = "Administrateur";
public static final String KEY_ADMINISTRATEUR_EMAIL = "Email";
public static final String KEY_ADMINISTRATEUR_PASSWORD = "Password";


public static final String TABLE_SCORE = "Score";
public static final String KEY_SCORE_ID_JEU = "IDJeu";
public static final String KEY_SCORE_USERNAME = "Username";
public static final String KEY_SCORE_SCORE = "Score";
public static final String KEY_SCORE_INITIALES = "Initiales";

public static final String TABLE_UTILISATEUR = "Utilisateur";
public static final String KEY_UTILISATEUR_USERNAME = "Username";
public static final String KEY_UTILISATEUR_PASSWORD = "Password";

public static final String TABLE_JEU = "jeu";
public static final String KEY_JEU_ID_JEU = "IDJeu";
public static final String KEY_JEU_NOM_JEU = "NomJeu";
public static final String KEY_JEU_COMMENTAIRES = "Commentaires";


private DBHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;


private static class DBHelper extends SQLiteOpenHelper {

    public DBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(android.database.sqlite.SQLiteDatabase nb) {
        //TODO check teh constraints and the relations
        nb.execSQL("CREATE TABLE " + TABLE_CATEGORIE + " (" +
                KEY_CATEGORIE_ID_CATEGORIE + " INTEGER PRIMARY KEY    AUTOINCREMENT, " +
                KEY_CATEGORIE_NOM_CATEGORIE + " TEXT NOT NULL" +     ");"
                );

        nb.execSQL("CREATE TABLE " + TABLE_MOT + " (" +
                KEY_MOT_ID_MOT + " INTEGER PRIMARY KEY     AUTOINCREMENT, " +
                KEY_MOT_MOT + " TEXT NOT NULL," + 
                KEY_MOT_EMAIL + " TEXT NOT NULL," + 
                KEY_MOT_ID_CATEGORIE + " TEXT NOT NULL," + 
                "FOREIGN KEY(" + KEY_MOT_ID_CATEGORIE + ") REFERENCES " + TABLE_CATEGORIE + "(" + KEY_CATEGORIE_ID_CATEGORIE  + ")," +
                "FOREIGN KEY(" + KEY_MOT_EMAIL + ") REFERENCES " + TABLE_ADMINISTRATEUR + "(" + KEY_ADMINISTRATEUR_EMAIL  + ")" +
                ");"
                );

        nb.execSQL("CREATE TABLE " + TABLE_ADMINISTRATEUR + " (" +
                KEY_ADMINISTRATEUR_EMAIL + " TEXT PRIMARY KEY , " +
                KEY_ADMINISTRATEUR_PASSWORD + " TEXT NOT NULL" +     ");"
                );

        nb.execSQL("CREATE TABLE " + TABLE_SCORE + " (" +
                KEY_SCORE_ID_JEU + " TEXT NOT NULL, " +
                KEY_SCORE_USERNAME + " TEXT NOT NULL," + 
                KEY_SCORE_SCORE + " INTEGER NOT NULL," + 
                KEY_SCORE_INITIALES + " TEXT NOT NULL," + 
                "FOREIGN KEY(" + KEY_SCORE_ID_JEU + ") REFERENCES "      + TABLE_JEU + "(" + KEY_JEU_ID_JEU  + ")," +
                "FOREIGN KEY(" + KEY_SCORE_USERNAME + ") REFERENCES      " + TABLE_UTILISATEUR + "(" + KEY_UTILISATEUR_USERNAME  + ")" +
                ");"
                );

        nb.execSQL("CREATE TABLE " + TABLE_UTILISATEUR + " (" +
                KEY_UTILISATEUR_USERNAME + " TEXT PRIMARY KEY , " +
                KEY_UTILISATEUR_PASSWORD + " TEXT NOT NULL" + ");"
                );
        nb.execSQL("CREATE TABLE " + TABLE_JEU + " (" +
                KEY_JEU_ID_JEU + " INTEGER PRIMARY KEY     AUTOINCREMENT, " +
                KEY_JEU_NOM_JEU + " TEXT NOT NULL UNIQUE," + 
                KEY_JEU_COMMENTAIRES + " TEXT" + 
                ");"
                ); 
    }

    @Override
    public void onUpgrade(android.database.sqlite.SQLiteDatabase db,
            int oldversion, int newversion) {
    //  db.execSQL("DROP TABLE IF EXISTS " + TABLE_CATEGORIE);
    //  onCreate(db);
    }

}

    public Database2(Context c){
        ourContext = c;
    }

    public Database2 open() throws SQLException {
        ourHelper = new DBHelper(ourContext);
        ourDatabase = ourHelper.getWritableDatabase();
        return this;
    }

    public void close() throws SQLException{
        ourHelper.close();
    }       

    public long createCategorie(String name) {
        ContentValues cv = new ContentValues();
        cv.put(KEY_CATEGORIE_NOM_CATEGORIE, name);
        return ourDatabase.insert(TABLE_CATEGORIE, null, cv);   
    }

    public String getCategorieData(){
        String result = "";
        String[] columns = new String[] {KEY_CATEGORIE_ID_CATEGORIE,     KEY_CATEGORIE_NOM_CATEGORIE};
        Cursor c = ourDatabase.query(TABLE_CATEGORIE, columns,null, null,     null, null, null);

        int id = c.getColumnIndex(KEY_CATEGORIE_ID_CATEGORIE);
        int name = c.getColumnIndex(KEY_CATEGORIE_NOM_CATEGORIE);

        for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
            result += c.getString(id) + " " + c.getString(name) + "\n";
        }

        return result;
    }

    }

`

Event Manager :



package com.jeux;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Jeuxdemots2Activity extends Activity implements OnClickListener {


  Button sqlUpdate, sqlView;
  EditText nameText;

  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  sqlUpdate = (Button) findViewById(R.id.updatebutton);
  sqlView = (Button) findViewById(R.id.afficherbutton);
  nameText = (EditText) findViewById(R.id.nametext);

  sqlUpdate.setOnClickListener(this);
  sqlView.setOnClickListener(this);    
  }

@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub

    switch (arg0.getId()){
    case R.id.updatebutton:
        try{
    String name = nameText.getText().toString();
    Database2 entry = new Database2(Jeuxdemots2Activity.this);
    entry.open();
    entry.createCategorie(name);
    entry.close();
        }catch (Exception e){
            String error = e.toString();

            Dialog d = new Dialog(this);
            d.setTitle("Dang it!");
            TextView tv = new TextView(this);
            tv.setText(error);
            d.setContentView(tv);
            d.show();
        }finally{

        }


    break;

    case R.id.afficherbutton:
        Intent i = new Intent("android.intent.action.SQLVIEW");
        startActivity(i);
    break;

    }


}
}

`

view #3 :

package com.jeux;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class SQLview extends Activity {

protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.afficherlayout);
    TextView tv = (TextView) findViewById(R.id.affichertextview);
    Database2 info = new Database2(this);
    info.open();
    String data = info.getCategorieData();
    info.close();
    tv.setText(data);
}
}

A photo to put context to my situation

  • 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-02T14:31:19+00:00Added an answer on June 2, 2026 at 2:31 pm

    When you close/re-open your virtual device, does it look like it’s doing a full bootup every time (Shiny Android word, swipe to unlock screen, etc)? If so, it could be re-initializing everything everytime you run your application. If so, you’re application and database are no longer on the device, so the data wouldn’t persist.

    When you create your emulator are you checking the “Snapshot” option? I believe that saves the state of your device into a file so that when you close/re-open your emulator, it’s able to resume from the same point.

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

Sidebar

Related Questions

How save insert sctipts in separate sql files in MySqlWorkbent? I can create database
I am aware that you can generate create scripts to generate database objects, but
I created a SQLite database on Android device. The program can read/write to database
Database gets created just fine, and the insert works just fine. I'm having problem
Its regarding QTP can we create database checkpoints for Web applications actually while creating
Can we create a new MySQL database( not a table, I want a new
I want to create a large database of GPS coordinates that can be queried
How can I build a query with this format with a sqlite3 database? CREATE
Suppose I am designing a class that can handle any database technology to create
Trying to simple update a row in an SQLiteDatabase Database. I can insert records

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.