FAQ Database Discussion Community


onCreate() method of SQLiteHelper is never called

java,android,android-sqlite,oncreate,sqliteopenhelper
I'm creating a database in android using SQLite. I wrote my code to create a table called products in onCreate() method. Then when I call add() method to add some values into the table, I'm getting an error that there is no such table called products. Here is my SQLiteHelper...

SQLiteException no such table ITEMS (code1) : while compiling: SELECT * FROM ITEMS WHERE RECID =?

android,sqlite,foreign-keys,sqliteopenhelper
I'm trying to create a table ITEMS with a FOREIGN KEY that references the id of another table UTILISATEURS... While my table UTILISATEURS works just fine, the table ITEMS is not created for some reason. The error seems to be in the following query : SELECT * FROM ITEMS WHERE...

How to insert data in SQLite database on android

android,sqlite,sqliteopenhelper
I am trying to insert data in a database table signals, which has 5 columns(id,SSID,BSSID, RSSID, Poloha). I am getting an Error in Logcat: E/SQLiteLog﹕ (1) table signals has no column named RSSID E/SQLiteDatabase﹕ Error inserting BSSID=a0:f3:c1:d4:c0:79 RSSID=49 SSID=AIESECFlat Poloha=PCstol android.database.sqlite.SQLiteException: table signals has no column named RSSID (code 1):...

What is the new way of creating sql lite open helper class in android

android,sql,sqliteopenhelper
I am new in android developer I used to use in sql lite open helper but lately I heard about a new way of creating sql lite database (maybe it's not true, I don't know ) I will be glad to hear if you guys know something about it. Thanks...

object of SQLiteOpenHelper only can be declared in onAttach and null elsewhere

android,android-fragments,android-sqlite,sqliteopenhelper
i have a class that extends SQLiteOpenHelper, in the activity, i declared the variables MQTT_Settings_DB and SQLiteDatabase as shown beow in the code. the problem is when i declared the variable MQTT_Settings_DB and initialised globally as show shown in the code, at run time, this line this.sqliteDB = this.mqttSettingsDB.getWritableDatabase(); that...

Database is created for emulator but not for android device

android,database,emulator,device,sqliteopenhelper
I am making an android app in which database is created with sqlite open helper. when I installed my app in emulator it works fine but when I did the same thing to test in my phone I don't see any database created in DDMS file explorer view data/data. It...

How to use two sqlite database within single application and how to use join operation with them?

android,sqlite,sqliteopenhelper
I have read many questions & answers related to my question but I am not getting a proper way for doing this. Condtion: I have three tables in SQLite database. I want to update the data of two (TBL_NAMES,TBL_CATEGORY) tables without losing the data of third table (TBL_FEVORITE) whenever my...

No such table found even though app successfully opens database from assets folder

java,android,sqlite,android-sqlite,sqliteopenhelper
I'm new to android development. I'm trying to use a pre-populated database whoch is stored in my assets folder. Log shows that the database gets opened but 'NO SUCH TABLE ERROR' is shown.I can't find any solution to this error. Please help. MyDatabase.java : package com.example.android.atlas; import android.content.Context; import android.database.Cursor;...

Android - How to access already created database from other class?

java,android,android-sqlite,sqliteopenhelper
Here is my SQLiteOpenHelper class : public class MySQLiteHelper extends SQLiteOpenHelper { ... //all the code SQLiteDatabase db; String url; String title; String init_price; String cur_price; byte[] image; // Database Version private static final int DATABASE_VERSION = 1; // Database Name private static final String DATABASE_NAME = "ProductsDB"; // Products...

No Such Table Error in SQLite

sqlite,android-activity,android-sqlite,sqliteopenhelper
There are already a few posts on this forum addressing this SQLite problem. However, I was not finding any convincing solutions as far I have searched. Hence I am posting a similar issue I am facing. I believe this question won't be marked as duplicate. So here is the issue....

Android: Rerun Database onCreate() if it fails

android,android-sqlite,sqliteopenhelper,android-database
Because of some poor decisions, I am stuck with an onCreate() in my SQLiteOpenHelper class that can run for up to 5 minutes. The user could turn off his phone, or force close the app during this process, meaning my onCreate() will be canceled prematurely. If that is the case...

Getting Context from a fragment - NullPointerException?

android,android-fragments,nullpointerexception,sqliteopenhelper
I tried to get activity's context from Fragment's onAttach() method. @Override public void onAttach(Activity activity) { super.onAttach(activity); context = activity.getApplicationContext(); obj = new MySQLiteHelper(context); ... } But, I'm still getting NullPointerException. How should I structure my code to avoid this? Here is my Fragment code : public class ListTab extends...

How to initiate the call onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)?

android,upgrade,sqliteopenhelper
I need to upgrade my android sqlite database from version 1 to version 2. But I do not understand how the call public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)is initiated? How and when will this method be called? I don't understand where I pass the Version number 2? [EDIT]...

Will onUpgrade be called for each increment?

android,sqlite,sqliteopenhelper
Assume i have my app's database version 1 running on some user device for a while. in the meantime i increment database version to 2, and then to 3 and handle onUpgrade like that : if (oldVersion == 1 && newVersion == 2) { db.execSQL(String.format("ALTER TABLE ... ADD .. text",...

ListView OnItemClickListener with a new Activity

android,listview,android-activity,onitemclicklistener,sqliteopenhelper
I have the first activity with this code: lvlitems.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //Toast.makeText(BuscarNota.this, "Clicked"+ id, Toast.LENGTH_SHORT).show(); Intent intent= new Intent(); intent.setClass(BuscarNota.this, Mostrar.class); intent.putExtra("id_nota", id); startActivityForResult(intent, 0); } }); And then I have the second activity with this code: EditText...

Android Sqlite : assign one column's values to another using ContentValues

android,database,sqlite,android-sqlite,sqliteopenhelper
I want to assign one column's values to another. here is a query for it. UPDATE contacts SET contactName=phone; Here contactName and phone are two different columns.i am assigning phone column's values to contactName column.I can do this by using db.execSQL(statement); but if i want it to update it using...

Can't use SQLite Default while onCreate

android,android-sqlite,sqliteopenhelper
i am having a issue with the Android SQLite Database. I want to set some default values, when i create the database with onCreate(). The database gets created but the table is empty. //Datenbank anlegen private static final String CREATETABLE_SETTINGS = "CREATE TABLE " + TABLE_SETTINGS + " (\n" +...

Getting all database entries from android database

android,sqlite,android-sqlite,sqliteopenhelper
I have an android project, with a database where entries are logged as pairs with the same ID. I have two for loops, one to get all entries of a certain ID, and one to get all entries in the table. These are then automatically populated into a listview. The...