Menu
  • HOME
  • TAGS

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

java,android,sqlite,android-sqlite,sqliteopenhelper

you should copy the .db file from your assets folder to an internal/external storage. You can use following codes, private static String DB_PATH = "/data/data/your package/database/"; private static String DB_NAME ="final.db";// Database name To create a database, public void createDataBase() throws IOException { //If database not exists copy it from...

getReadableDatabase get database called recursively

android,android-sqlite,sqliteopenhelper

Your fill...() methods likely call getWritableDatabase(). You call the fill...() methods in onCreate() that is triggered by a call to getWritableDatabase() or getReadableDatabase(). That causes the recursion: you're calling get...Database() while a previous call to it has not yet completed. Use the SQLiteDatabase passed in as an argument to onCreate()...

Android SQLiteOpenHelper onUpdate doesn't drop table with rows

android,sqliteopenhelper

String dropQuery = "Drop Table " + EventsTable.TABLE_NAME + ";"; dropQuery += " Drop Table " + UsersTable.TABLE_NAME + ";"; You are trying to execute multiple SQL statement which is not allowed in sqlite. I suggest you to execute both drop table sql statement separately. String dropQuery = "Drop Table...

Store Integer in SQL Database & Retrieve it in Fragment

java,android,android-fragments,sqliteopenhelper,store-data

If you just want to store a Integer, maybe you could take a look to the DefaultSharedPreferences class. See this link : http://developer.android.com/reference/android/content/SharedPreferences.html if you are doing this from your fragment: SharedPreferences pref = getActivity().getSharedPreferences("keyname", Context.MODE_PRIVATE); SharedPreferences.Editor editor = pref.edit(); editor.putInt("counter", integer); editor.commit(); Then when you want to retrieve it,...

cannot bind argument at index because the index is out of range

android,sqlite,android-activity,android-sqlite,sqliteopenhelper

db.query(TABLE_TOURS, // a. table tableColumns, // b. column names COLUMN_TITLE+ " like '"+tour.getTitle()+"'", // c. selections new String[] { COLUMN_TITLE }, // d. selections args Selection args work only when you actually have parameters in the selection: db.query(... COLUMN_TITLE+ " like ?", // c. selections new String[] { tour.getTitle() },...

Should simultaneously having multiple different SQLite Database Versions be considered harmful?

android,sqlite,oncreate,sqliteopenhelper,database-versioning

I am breaking out each SQLite table's code (including initial construction of the table as well as operations on that table) into separate classes extending SQLiteOpenHelper It is important, for thread safety among other reasons, to have a single instance of SQLiteDatabase that you use consistently. That in turn,...

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

java,android,android-sqlite,sqliteopenhelper

MySQLiteHelper has no method for getLength() but that is ok. (more on this at the end) the read() method is not public, and it really does nothing other than populate the table member/field of the MySQLiteHelper class. You aren't leveraging the getTable() method you created (which also is not...

SQLiteAssetHelper database file size

android,sqlite,sqliteopenhelper

I ended up using text files for the major lookup tables in my database. I added them in the assets folder, along with the smaller sqlite db. I kept only the small tables that I needed to do inserts/adds in the sqlite db. And I was also able to easily...

No Such Table Error in SQLite

sqlite,android-activity,android-sqlite,sqliteopenhelper

You miss some commas to separate the next fields: "CREATE TABLE " + TABLE_NAME_INVENTORY + "( " + COLUMN_INVENTORY_UID + " INTEGER PRIMARY KEY AUTOINCREMENT," + " " + COLUMN_INVENTORY_NAME + " VARCHAR(255)," + " " + COLUMN_INVENTORY_COST_PRICE + " VARCHAR(255)," + " " + COLUMN_INVENTORY_SALE_PRICE + " VARCHAR(255)" +...

Can't use SQLite Default while onCreate

android,android-sqlite,sqliteopenhelper

DEFAULT in a column definition is only applied if no or a null value is supplied for a column when inserting or updating rows. The code you posted does not insert any rows. To insert a row with default values, consider "INSERT INTO " + TABLE_SETTINGS + "(id) VALUES(NULL)" (You...

How do I get the SQLite Database row_ID from the Gridview with onClicklistener?

android,sqlite,android-sqlite,android-gridview,sqliteopenhelper

You should pass into your adapter an arraylist of model objects; call it myArray. Populate the array with model objects that have a reference to the path you want. Then you can call myArray.get(position), that will give you a model object; call it myObject. Then call myObject.getPath(). Model Object: a...

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

android,upgrade,sqliteopenhelper

The SQLiteOpenHelper constructor takes a name and version number, and the helper will invoke the onCreate or onUpgrade callback as necessary. You need to maintain database version numbers yourself, bumping the version number when a schema change is necessary. When you need to update your database from version 1 to...

get Contex in extended SQLiteOpenHelper class

android,android-studio,android-sqlite,sqliteopenhelper

You're passing a Context as a constructor argument. Just store it to a member variable: private Context mContext; public DatabaseHelper(Context context) { super(context, dbName, null, dbv); mContext = context; and then use mContext where you need a Context....

Error Inserting: no such table error

android,android-sqlite,sqliteopenhelper

Problem is at creating the table. static final String KEY_ID = "_id"; static final String KEY_NAME= "name"; static final String DATABASE_NAME="MyDB"; static final String DATABASE_TABLE="contactlist"; static final int DATABASE_VERSION = 1; CHANGE FROM THIS static final String DATABASE_CREATE ="create table contactlist(_id integer primary key autoincrement," +"name text not null);"; TO...

ListView OnItemClickListener with a new Activity

android,listview,android-activity,onitemclicklistener,sqliteopenhelper

i just solve it. thanks EditText nota_input; MiDB dbHandler; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mostrar); nota_input= (EditText) findViewById(R.id.txtmostrar); dbHandler = new MiDB(this, null, null,1); int prePosition = (int) getIntent().getLongExtra("id_nota", 0); Cursor c = dbHandler.notasbyid(prePosition); nota_input.setText(c.getString(c.getColumnIndexOrThrow("nota"))); } ...

Database is created for emulator but not for android device

android,database,emulator,device,sqliteopenhelper

Root the android device or write a code for coping db file to sdcard Code for coping database from /data/data directory to sdcard public void copyDBToSDCard() { try { File sd = Environment.getExternalStorageDirectory(); File data = Environment.getDataDirectory(); if (sd.canWrite()) { String currentDBPath = "//data//"+getPackageName()+"//databases//"+DB_NAME+""; String backupDBPath = "backupname.db"; File currentDB...

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

android,android-fragments,android-sqlite,sqliteopenhelper

private MQTT_Settings_DB mqttSettingsDB = new MQTT_Settings_DB(getActivity()); getActivity() returns null before the fragment is attached to an activity. Passing null to a SQLiteOpenHelper constructor doesn't crash immediately but it will when you try to actually open the database with e.g. getWritableDatabase()....

Android: Rerun Database onCreate() if it fails

android,android-sqlite,sqliteopenhelper,android-database

Just create your tables in onCreate() and initialise the data in another Service or background thread. In that background thread, call beginTransaction() on your SQLiteDatabase object before you initialise the data. Then call setTransactionSuccessful() and endTransaction() when it has finished. Keep a flag in SharedPreferences so you can check if...

Will onUpgrade be called for each increment?

android,sqlite,sqliteopenhelper

i guess you can use: if (oldVersion == 1) { do stuff; oldVersion = oldVersion + 1; } if (oldVersion == 2) { do stuff; oldVersion = oldVersion + 1; } or use a switch....

How to insert data in SQLite database on android

android,sqlite,sqliteopenhelper

Add commas between your column specifications: + KEY_BSSID + " TEXT," + KEY_RSSID + " TEXT," and uninstall your app so that database helper onCreate() is rerun....

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

android,database,sqlite,android-sqlite,sqliteopenhelper

You can't use ContentValues for that. You can only update/insert literal values with ContentValues, not column name references. Just use execSQL() with the raw SQL you have. (Don't use rawQuery() - it alone won't execute your SQL.)...

Getting all database entries from android database

android,sqlite,android-sqlite,sqliteopenhelper

My guess is that in your database definition, you didn't specify the ID column as INTEGER NOT NULL. So when you select every row, one or more of those rows has a null ID, which you're trying to parse as an int here: assignment.setID(Integer.parseInt(cursor.getString(0))); Change your database definition to require...

Interfaces inside database class for declaring table and column names - good approach?

android,database-design,interface,sqliteopenhelper

Many people consider the Constant Interface to be an anti-pattern. It certainly works, but I find just as much success doing something like this: public final class Entity { public static final String TABLE = "table_name"; public static final String COLUMN_1 = "column1_name"; public static final String COLUMN_2 = "column2_name";...

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

android,sql,sqliteopenhelper

Unfortunately there is no new way. Here're all main moments for you to work with database in android: http://www.vogella.com/tutorials/AndroidSQLite/article.html

I can't get data from Cursor Object

android,android-sqlite,sqliteopenhelper

You need to move the cursor to a valid row. Valid rows are indexed from 0 to count-1. At first the cursor will point to row index -1 i.e. the one just before the first row. The canonical way of looping through all rows is if (cursor.moveToFirst()) { do {...

onCreate() method of SQLiteHelper is never called

java,android,android-sqlite,oncreate,sqliteopenhelper

This may help with future development MySQLiteHelper - Defines Database, tables etc. public class MySQLiteHelper extends SQLiteOpenHelper { private static final String FILE_NAME = "application.db"; private static final int DB_VERSION = 1; private final String TAG = MySQLiteHelper.class.getCanonicalName(); private static SQLiteDatabase database = null; public MySQLiteHelper(Context context) { super(context, FILE_NAME,...

How we can pass data?

java,android,sqliteopenhelper

You shouldn't instantiate activity classes this way. Use a separate class instead, where you can define methods which you'd like to use somewhere else. In your case, receiving package name, I'd do something like this public class PackageNameHelper { private Context mContext; public PackageNameHelper(Context context) { mContext = context; }...

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

android,sqlite,sqliteopenhelper

Im not sure if i understand your question, but you can't use SQL JOIN on two (or more) databases. You can only JOIN Tables of the same database. If you really want to JOIN databases, then you have to do that by hand i.e. query a list of records from...

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

android,sqlite,foreign-keys,sqliteopenhelper

I finally resolved my problem. If you are creating more than one table in the same Database, it is better to wrap them in same DbHelper, therefore creating them in the same DbHelper instanciation.

Getting Context from a fragment - NullPointerException?

android,android-fragments,nullpointerexception,sqliteopenhelper

Android provides you a getActivity() in a fragment for the same scenario. This is from the documentation for onAttach().The onCreate is called immedaitely after onAttach(). I think if you check the onCreate(),you could use that instead for your purpose. If you carefully read the fragment lifecycle,the activity's onActivityCreated onccurs after...

SQLiteOpenHelper translating SQLite query in Android

android,sqlite,sqliteopenhelper

Group by queries require a great deal of overhead on any database so use them sparingly. Group by is used to get sub totals and unique results. Assume that timestamp is unique for productid and supermarketid which it probably is so we don't need the group by clause. SQL like...

SQLite - Can't retrieve all values - getString(int index) is not working

android,database,sqlite,android-sqlite,sqliteopenhelper

Replace lines of code like this: place.setname(cursor.getString(1)); With something like this: place.setname(cursor.getString(cursor.getColumnIndex(KEY_PLACENAME))); It looks like the column corresponding to KEY_PLACEDETAILS is actually the 2nd column, and you're trying to get something from the 4th column. Using cursor.getColumnIndex() to get the column matching with each key is safer anyways, in case...

Is there a way to stash an entire SQLite query result into a string?

sqlite,android-sqlite,sqliteopenhelper,dynamicquery

You might do better to use the StringBuilder class like this (note this gives you one huge string, not an array of strings; if you want an array where each row of the cursor is it's own element, then declare results as an ArrayList, replace results.append with results.add and return...

Proper way to copy database from /assets to app's private storage

android,database,sqliteopenhelper

I suggest the SQLiteAssetHelper library from: https://github.com/jgilfelt/android-sqlite-asset-helper It has become the standard for this technique, and does all the hard work for you. And integration into your project is as simple as including 1 jar file. For example, here is my database helper class - as you can see it...