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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:16:26+00:00 2026-06-12T06:16:26+00:00

Im a beginner in Android and this datamanipulator allows me to insert data into

  • 0

Im a beginner in Android and this datamanipulator allows me to insert data into the 1st table (“People”), however i can not make it work to add data into the 2nd table (“appointments”) using a 2nd method, a 2nd string “insert2”. However the data is inserted into the 1st table and not the 2nd table. Any ideas of what I’m doing wrong? Thx in advance!

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 android.widget.Toast;
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";
static final String TABLE_NAME2 = "Citas";
private static Context context;
private static Context context2;
static SQLiteDatabase db;
private SQLiteStatement insertStmt;
private static final String INSERT = "insert into " + TABLE_NAME + " (nombre,cedula,fechanacimiento,telefonocasa,telefonomovil,tipo) values (?,?,?,?,?,?)";
private static final String INSERT2 = "insert into " + TABLE_NAME2 + " (nombrepaciente,fechacita,horacita,nombredoctor) 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  void DataManipulator(Context context2) {
    DataManipulator.context2 = context2;
    OpenHelper openHelper = new OpenHelper(DataManipulator.context2);
    DataManipulator.db = openHelper.getWritableDatabase();
    this.insertStmt = DataManipulator.db.compileStatement(INSERT2);
}

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 long insert2(String nombrepaciente,String fechacita,String horacita,String nombredoctor) {
    this.insertStmt.bindString(1, nombrepaciente);
    this.insertStmt.bindString(2, fechacita);
    this.insertStmt.bindString(3, horacita);
    this.insertStmt.bindString(4, nombredoctor);
    //this.insertStmt.bindString(5, telefonomovil);
    //this.insertStmt.bindString(6, tipo);
    return this.insertStmt.executeInsert();
}

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

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)");
         //B) FINAL NO QUITAR
         db.execSQL("CREATE TABLE " + TABLE_NAME2 + " (id INTEGER PRIMARY KEY, nombrepaciente TEXT, fechacita TEXT, horacita TEXT, nombredoctor TEXT)");
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
    {
         db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
         onCreate(db);
    }
}
}
  • 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-12T06:16:27+00:00Added an answer on June 12, 2026 at 6:16 am

    You cannot have two methods that take identical parameters:

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

    Try passing a flag instead:

    public DataManipulator(Context context, boolean first) {
        DataManipulator.context = context;
        OpenHelper openHelper = new OpenHelper(DataManipulator.context);
        DataManipulator.db = openHelper.getWritableDatabase();
    
        if(first)
            this.insertStmt = DataManipulator.db.compileStatement(INSERT);
        else
            this.insertStmt = DataManipulator.db.compileStatement(INSERT2);
    }
    

    Alternatively, you should consider creating two different handler classes, one for each table.

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

Sidebar

Related Questions

I'm a beginner in Android development but not in programming itself. Anyway, this question
Android beginner, Can anybody guide me on this ? I do have the distance,
I am a beginner in both Java and Android, and I think this is
I am implementing a Database for my (beginner/Android) application. It is not clear to
I'm just a beginner with android. I want to divide a bitmap image into
I'm a beginner android developer , I was trying to run this Linear Layout
I'm a beginner in Android. Here I have this code: public class GPS extends
I am beginner of Android OpenGL I want to learn and make Live wallpaper
I am a beginner in android.I can able to change the font type of
I am a beginner in Android. I am developing one animated game in Activity(not

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.