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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:04:16+00:00 2026-06-05T19:04:16+00:00

I was newbie in using sqlite database android. and now I have a problem

  • 0

I was newbie in using sqlite database android. and now I have a problem with my sqlite database in android,
first i create first table :

        private static final String CREATE_TABLE_MASTER = "create table"
        + TABLE_MASTER + " (" + MASTER_ID
        + " integer primary key autoincrement, " + NAMA_MASALAH
        + " Integer not null, " + JLH_KRITERIA + " Integer not null, "
        + JLH_ALTERNATIVE + " text not null);";

it wass success, but when i create the second table :

    private static final String CREATE_TABLE_KRITERIA = "create table if not exist "
    +TABLE_KRITERIA+ "("+ KRITERIA_ID
    + "integer primary key autoincrement, " 
    +KRITERIA_NAMA+ "text);";

but it was error, and in the LogCat it said :

No such table: tableKriteria: while compiling: select idKriteria, namaKriteria From tableKriteria

here the full code of my SQLiteAdapter.java :

package com.MFrameworkAHP;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

public class SQLiteAdapter {
public static final String NAMA_DATABASE = "MY_DATABASE";
public static final String TABLE_MASTER = "MY_TABLE";
public static final int MYDATABASE_VERSION = 1;
public static final String MASTER_ID = "_id";
public static final String NAMA_MASALAH = "Content1";
public static final String JLH_KRITERIA = "Content2";
public static final String JLH_ALTERNATIVE = "Content3";

public static final String TABLE_KRITERIA = "tableKriteria";
public static final String KRITERIA_ID= "idKriteria";
public static final String KRITERIA_NAMA = "namaKriteria";
public static final String KRITERIA_IDDATA = "idDataKriteria";


// create table MY_DATABASE (ID integer primary key, Content text not null);
private static final String CREATE_TABLE_MASTER = "create table"
        + TABLE_MASTER + " (" + MASTER_ID
        + " integer primary key autoincrement, " + NAMA_MASALAH
        + " Integer not null, " + JLH_KRITERIA + " Integer not null, "
        + JLH_ALTERNATIVE + " text not null);";

private static final String CREATE_TABLE_KRITERIA = "create table if not exist "
    +TABLE_KRITERIA+ "("+ KRITERIA_ID
    + "integer primary key autoincrement, " 
    +KRITERIA_NAMA+ "text);";

;
//private static final String

private SQLiteHelper sqLiteHelper;
private SQLiteDatabase sqLiteDatabase;
private Context context;

public SQLiteAdapter(Context c) {
    context = c;
}

public SQLiteAdapter openToRead() throws android.database.SQLException {
    sqLiteHelper = new SQLiteHelper(context, NAMA_DATABASE, null,
            MYDATABASE_VERSION);
    sqLiteDatabase = sqLiteHelper.getReadableDatabase();
    return this;
}

public SQLiteAdapter openToWrite() throws android.database.SQLException {
    sqLiteHelper = new SQLiteHelper(context, NAMA_DATABASE, null,
            MYDATABASE_VERSION);
    sqLiteDatabase = sqLiteHelper.getWritableDatabase();
    return this;
}

public void close() {
    sqLiteHelper.close();
}

public long insert(String namaMasalah, String jlhKriteria, String jlhAlternative) {
    ContentValues contentValues = new ContentValues();
    contentValues.put(NAMA_MASALAH, namaMasalah);
    contentValues.put(JLH_KRITERIA, jlhKriteria);
    contentValues.put(JLH_ALTERNATIVE, jlhAlternative);
    return sqLiteDatabase.insert(TABLE_MASTER, null, contentValues);
}

public long insertKriteria(String namaKriteria){
    ContentValues cv = new ContentValues();
    //cv.put(KRITERIA_ID, idKriteria);
    cv.put(KRITERIA_NAMA,namaKriteria);

    return sqLiteDatabase.insert(TABLE_KRITERIA, null, cv);
}
public int deleteAll() {
    return  sqLiteDatabase.delete(TABLE_MASTER, null, null);

}

public void delete_byID(int id) {
    sqLiteDatabase.delete(TABLE_MASTER, MASTER_ID + "=" + id, null);
}

public void update_byID(int id, String v1, String v2, String v3) {
    ContentValues values = new ContentValues();
    values.put(NAMA_MASALAH, v1);
    values.put(JLH_KRITERIA, v2);
    values.put(JLH_ALTERNATIVE, v3);
    sqLiteDatabase
            .update(TABLE_MASTER, values, MASTER_ID + "=" + id, null);
}

public Cursor queueAll() {
    String[] columns = new String[] { MASTER_ID, NAMA_MASALAH, JLH_KRITERIA,
            JLH_ALTERNATIVE };
    Cursor cursor = sqLiteDatabase.query(TABLE_MASTER, columns, null,
            null, null, null, null);
    return cursor;
}

public Cursor queueKriteria() {
    String[] columns = new String[] { KRITERIA_ID, KRITERIA_NAMA };
    Cursor cursor = sqLiteDatabase.query(TABLE_KRITERIA, columns, null,
            null, null, null, null);
    return cursor;
}

public Cursor queueAll_SortBy_namaMasalah() {
    String[] columns = new String[] { MASTER_ID, NAMA_MASALAH, JLH_KRITERIA,
            JLH_ALTERNATIVE };
    Cursor cursor = sqLiteDatabase.query(TABLE_MASTER, columns, null,
            null, null, null, NAMA_MASALAH);

    return cursor;
}

public class SQLiteHelper extends SQLiteOpenHelper {
    public SQLiteHelper(Context context, String name,
            CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL(CREATE_TABLE_KRITERIA);
        db.execSQL(CREATE_TABLE_MASTER);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
    }

}

}

I had tried all about one weeks to solve my problems, like changed the database version, changed the create statement for the second table, etc. but it didn’t work 🙁
there are many question in this forum as same with my question, but it couldn’t solve my problem, like here, here , etc.

guys, please help me,. .

thanks before .

  • 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-05T19:04:17+00:00Added an answer on June 5, 2026 at 7:04 pm

    It seems you might need to add some spaces to the ‘create’ string. Also it should be exists and not exist. Try…

    private static final String CREATE_TABLE_KRITERIA = "create table if not exists "
    +TABLE_KRITERIA+ " ("+ KRITERIA_ID
    + " integer primary key autoincrement, " 
    +KRITERIA_NAMA+ " text);";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a newbie using asp.net I have a problem on what I am
I am a newbie in using asp.net, I have a problem on how to
I have been using the System.Data.SQLite provider for my application. When I try to
.NET newbie alert Using Visual C# 2008 Express Edition I have accidentally created a
I am a newbie using C++ and I have a background with Java I
I'm a newbie using Extjs 4.07. I have created a combobox (remote) queryMode. The
Hello I am a newbie using F# and MySQL. I have a project that
I am quite newbie in using eclipse cdt. I have a makefile project, and
I am newbie for hibernate,i am using mysql database,with two tables serviceTypeDetails,validateConfig.In serviceTypeDetails,it's having
1st i'm newbie I import object/Class using lazy() now my questions are 1) what

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.