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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:25:42+00:00 2026-06-11T19:25:42+00:00

This datamanipulator allows me to: 1. Create table Personas (people) and i can add

  • 0

This datamanipulator allows me to:
1. Create table Personas (“people”) and i can add pacients and doctors without any issue.

package com.example.citas.medicas;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;
import java.util.ArrayList;
import java.util.List;

public class DataManipulator
{
private static final  String DATABASE_NAME = "mydatabase.db";
private static final int DATABASE_VERSION = 1;
static final String TABLE_NAME = "Personas";
private static Context context;
static SQLiteDatabase db;
private SQLiteStatement insertStmt;
private static final String INSERT = "insert into " + TABLE_NAME + " (nombre,cedula,fechanacimiento,telefonocasa,telefonomovil,tipo) values (?,?,?,?,?,?)";

public DataManipulator(Context context) {
    DataManipulator.context = context;
    OpenHelper openHelper = new OpenHelper(DataManipulator.context);
    DataManipulator.db = openHelper.getWritableDatabase();
    this.insertStmt = DataManipulator.db.compileStatement(INSERT);
}

public long insert(String nombre,String cedula,String fechanacimiento,String telefonocasa,String telefonomovil,String tipo) {
    this.insertStmt.bindString(1, nombre);
    this.insertStmt.bindString(2, cedula);
    this.insertStmt.bindString(3, fechanacimiento);
    this.insertStmt.bindString(4, telefonocasa);
    this.insertStmt.bindString(5, telefonomovil);
    this.insertStmt.bindString(6, tipo);
    return this.insertStmt.executeInsert();
}

public void deleteAll() {
    db.delete(TABLE_NAME, null, null);
}

public List<String[]> selectAll()
{
    List<String[]> list = new ArrayList<String[]>();
    Cursor cursor = db.query(TABLE_NAME, new String[] { "id","nombre","cedula","fechanacimiento","telefonocasa","telefonomovil","tipo" }, null, null, null, null, "name asc"); 
    int x=0;
    if (cursor.moveToFirst()) {
       do {
            String[] b1=new String[]{cursor.getString(0),cursor.getString(1),cursor.getString(2),
            cursor.getString(3),cursor.getString(4),cursor.getString(5),cursor.getString(6)};
            list.add(b1);
            x=x+1;
       } while (cursor.moveToNext());
    }
    if (cursor != null && !cursor.isClosed()) {
       cursor.close();
    } 
    cursor.close();
    return list;
}

public void delete(int rowId) {
    db.delete(TABLE_NAME, null, null); 
}

private static class OpenHelper extends SQLiteOpenHelper {
    OpenHelper(Context context) {
         super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
         db.execSQL("CREATE TABLE " + TABLE_NAME + " (id INTEGER PRIMARY KEY, nombre TEXT, cedula TEXT, fechanacimiento TEXT, telefonocasa TEXT, telefonomovil TEXT, tipo TEXT)");
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
    {
         db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
         onCreate(db);
    }
}
}

BUT when i use this 2nd “datamanipulator2” (copy-paste from the 1st data manipulator), its supposed to create the table Citas (“appointments”) so i can add an appointment but it gaves an error saying:

09-23 22:40:57.202: E/AndroidRuntime(889): android.database.sqlite.SQLiteException: no such table: Citas: , while compiling: insert into Citas (nombrepaciente,fechacita,horacita,nombredoctor) values (?,?,?,?)

I noticed i can fix this if i change (in the “datamanipulator2”) the db version to 2

DATABASE_VERSION = 2;

but i would like to know: A) another way to avoid this error, i mean, i would like to keep both datamanipulators with “DATABASE_VERSION = 1;” which i think it sounds better to me in general, unless is completely necessary that “datamanipulator” has a value of 1 and the “datamanipulator2” has a value of 2. B) why this is happening? is this a normal behavior?

  • 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-11T19:25:43+00:00Added an answer on June 11, 2026 at 7:25 pm

    If you look at the class SQLiteOpenHelper, onCreate is only called when the database is created the first time. onUpgrade is called if the version of the database is changed. The changing of the version serves exactly that purpose – gives a hook to create additional tables, etc.

    So, there are 2 choices:
    1. Remove the database completely before re-installing your application so that both tables are created at version 1.
    2. Keep incrementing the version as you add more tables.

    In the development cycle, I would recommend using option 1.

    Hope this helps…

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

Sidebar

Related Questions

This is a super simple issue that I can't figure out. I want to
This code below allows me to find the word error in all my files
This question is about WordPress cms. How to create a new admin user with
This question was posted on StackApps , but the issue may be more a
This is my database table. Now I want to combine Branch_Id, Acc_no and Acc_Type
This seems 101-level, but I can't find an answer! (instead I find links to
This is a bit of a long shot, but if anyone can figure it
This is my code to add sprites on Scene. for (int i = 3;
This is what I tried to do ten times today without success: make a
This question should be rather easy for any Java developer. I swear I looked

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.