FAQ Database Discussion Community


Android - When to use Shared Preferences and when to use SQLite

java,android,android-studio,sharedpreferences,android-sqlite
I have created a food calories app, where users can enter foods and weights and my app will calculate the total calories. I have also created a 'Save' button, which when pressed will take the calories just calculated and display it on the Main Activity. When the 'Save' button is...

Unable to display sqllite data into Table Layout

android,android-sqlite,android-database
I am new to Android. I'm trying to display the data in a tabular form, loading data from thedatabase`. But it is showing the following error: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. at android.database.CursorWindow.nativeGetString(Native Method)...

Android Studio Create Database error (android.database.sqlite.SQLiteException: near “and”: syntax error (code 1): ) Detailed Analysis

java,database,android-studio,android-sqlite
I'm trying to use the database and it complains about my "CREATE TABLE". I looked at different posts and "updated mine on here for the changes I made to CREATE TABLE). It looks correct compared to other posts and forums, so I am not quite sure why it keeps failing....

sqlite query - select data which prefers some value

sql,android-sqlite
I'm trying to create an sqlite query but I'm having some problems. Let's say that table has three columns id, foreign-id and value. I need to select all rows with distinct foreign_id with a given value, however that value may not exist for all different foreign_ids. In which case a...

How to retrieve a specific row using SQLite and Cursors?

android,android-sqlite,android-cursor
I want to retrieve a specific user from a SQLite database on Android with a provided username using a Cursor. I've tried this: String[] fields = new String[] { "username", "email", "dateRegister" }; Cursor c = db.query(tableName, fields, "username ='1234'", null); But it isn't working. How can I retrieve a...

no such column error - sqlite

android,sql,sqlite,select,android-sqlite
I get a strange error: E/SQLiteLog﹕ (1) no such column: Test 06-22 01:51:20.006 15089-15089/com.almas.mehr.sms E/AndroidRuntime﹕ FATAL EXCEPTION: main android.database.sqlite.SQLiteException: no such column: Test (code 1): , while compiling: SELECT * FROM groups WHERE title = Test at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1090) at...

Adapter Subscribing to Multiple Observables

android,android-sqlite,baseadapter,rx-java,sqlbrite
My question is What is the best way for an Adapter to subscribe to multiple observables I have an Adapter that has a header and regular item types. The information for the adapter is fed from a database using Sqlbrite. Using Sqlbrite, I want to update the header and the...

getContext() cannot be resolved in SQLite dB

java,android,android-sqlite,android-contacts
I'm trying to create an SQL database to store local contact information (mainly just phone# (to be verify at a later time) and display name, along with a user-specified boolean. I created a new contactdb class, but I ran into some bumps when trying to use getcontext(). Secondary values for...

android sql table update error

android,sqlite,android-sqlite
When I try to update a table it does not return any error.But update not works. Here is my insert and update query Can anyone tell is there any problem? My insert statement (working) public long insertValueWithOnDate(int ParameterId,String value,String date,String operation) { ContentValues initialValues = new ContentValues(); initialValues.put(KEY_PARAMETER_ID, ParameterId); initialValues.put(KEY_UNIT_VALUE,...

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...

How to convert String to Date which can be store in database?

android,android-sqlite,android-datepicker,android-date
I use a DataPicker and in the method onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) I get year , monthOfYear and dayOfMonth, how I can merge this 3 int in a single Date which I can use to store in a database?

near synatx error (code 1) insert Android SQLite

android,sqlite,debugging,syntax,android-sqlite
I am creating a Contact Book app where users input name, email address and number. I want this data to be saved in a database, but I can't seem to get the insert method to work: The error I'm getting is: android.database.sqlite.SQLiteException: near "Number": syntax error (code 1): , while...

How to share and sync android sqlite database across devices when they are updated?

android,android-sqlite
I am a novice android app developer. Currently I am developing an app which has a sqlite database. Users store some data in that database. Now I want to add an online synchronization / data sharing feature in my app - If a user update his/her device's database( that means...

Robolectric accessing database throws an error

android,android-sqlite,robolectric
I have a test that creates an activity which attempts to get some data from the database. This fails with SQLiteException 17:40:40.528 [DEBUG] [TestEventLogger] android.database.sqlite.SQLiteException: Cannot open SQLite connection, base error code: 14 17:40:40.528 [DEBUG] [TestEventLogger] at org.robolectric.shadows.ShadowSQLiteConnection.rethrow(ShadowSQLiteConnection.java:53) 17:40:40.528 [DEBUG] [TestEventLogger] at org.robolectric.shadows.ShadowSQLiteConnection.access$600(ShadowSQLiteConnection.java:30) 17:40:40.529 [DEBUG]...

Is sharedPreference cleared when an android app is reinstalled?

android,sqlite,sharedpreferences,android-sqlite,android-install-apk
When we run an app during development on a device is sharedPreference cleared when app is reinstalled ?

Using SQLCipher with Android [duplicate]

android,encryption,android-sqlite,sqlcipher
This question is an exact duplicate of: Encrypt exisiting database in Android 1 answer I have previously asked this question and have not got any appropriate answer. I have an app published in the Play Store which makes heavy use of SQLite database. Now I need to secure the...

java.lang.numberFormatException: Invalid int “_id”

android,android-sqlite
I am trying add data to a table named as User Table. It has two columns Task and SubTask. Task should hold the _id value of Task Table and SubTask should hold the _id value of SubTask table. Hence I have referenced those two columns as foreign keys to this...

Unable to update TextView field inside RecyclerView

android,listview,android-sqlite,recyclerview
I'm migrating from ListView to an RecyclerView and last thing I'm stuck with is updating one of fields. My App has a simple list with some images found on internet. When you choose one, image gets downloaded to a phone for later offline viewing. Adapter gets data from SQLite databaseso...

How to check whether table is empty or not in android?

android,sql,android-sqlite
I want to add data to the table called allquestions but have to check whether it is null or it contains any data.When I add data,it gets added every time i run the application.I want to clear the previous data every time I start the application. db.execSQL("CREATE TABLE IF NOT...

If I install the app in another device, is it still possible to log in with the pre-made ID?

android,database,sqlite,sqlite3,android-sqlite
For my best knowledge so far, the biggest difference between SQLite and MySQL is that it does not require a server to run, as SQLite stores data in a database file in each device. The question rising from this part is.. Let's say I created an Android app which simply...

Will the Android device still run at the next startup if once happens a database locked

android-sqlite,locked
my friends: I am working on a Android App.In a cloud test, I found that some devices happened an error——"database is locked".Considering that i have not met the error,so i wonder that once the error happens on a device, will the device run nomally at the next startup.My worry is...

re write-sql statement Insert OR REPLACE from java to c++ NDK Android

c++,android-ndk,android-sqlite
I need re write this sqlite Statements from java to c++, BEcouse of low performance: I red this arcticle: Improve INSERT-per-second performance of SQLite? But Iam totaly confused, becouse I cant find any sqlstatemenst of Insert or Update public synchronized void saveMatchValue(int photoRecOwner, int[] photoRecAssign, float[] value) { SQLiteDatabase database...

Same SQLite Query doesnot run in all the android version

android,android-sqlite,android-version
I am executing the following query in the SQLite : SELECT * from ValueTable where SrNo = (with t as(SELECT SrNo,Value2 from ValueTable where Value2<'600' ) SELECT SrNo from t order by Value2 DESC limit 1) The table schema is SrNo Value1 Value2 1 200 450 2 500 350 3...

Android Error implementing CursorAdapter - Column _id

android,android-sqlite,android-cursoradapter
recently that I use sqlite in android and I have a problem not solved. I found a tutorial that explains how to run a database and works perfectly. I'm happy to have found. Now I want to implement a CursorAdapter to customize the listview containing the data of the DB...

Unable to convert BLOB to String using Loadermanager in android

android,android-sqlite
I have a table with following structure. public static final String TABLE_NAME = "contact"; public static final String ID = "_id"; public static final String DEVICE_ID = "device_id"; public static final String NAME = "name"; public static final String CONTACT = "contact"; public static final String IMAGE = "image"; private...

How to get checked radio button's id created dynamically in android

java,android,sqlite,android-sqlite,android-radiogroup
In my activity, I am creating a dynamic radiogroup. I have some questions and answers in Sqlite database, retrieving them in activity and then set in RadioGroup. This is working fine. But after that, I want to get all ID of selected radio button by user to store them in...

Progress Bar not animating while inserting data in Database using AsyncTask

android,sqlite,animation,android-asynctask,android-sqlite
I have edittext and button to insert data,when i click the button i am hiding the button and edittext and showing a ProgressBar.I am using AsyncTask to insert data in sqlite database, but the problem is, While performing background task,the ProgressBar is not animating.I am using progressbar with intermediateDrawable. NOTE:...

Android SQLite can a tables name be 'TABLE'

android,sql,android-sqlite,greendao
I'm using the GreenDAO ORM for SQLite, The problem i'm facing is that I have a table named TABLE, I use the following command to create the table : db.execSQL("CREATE TABLE 'TABLE' (" + // "'_id' INTEGER PRIMARY KEY ," + // 0: id "'TYPE' INTEGER NOT NULL ," +...

MATCH with selectArgs looking like *queryTerm* stopped working on Android 5.0+

android,android-sqlite,android-5.0-lollipop
This is addendum to my question SQLiteDatabase Cursor empty only on Android 5.0+ devices. That one will be closed as I was not sure what is causing the bug - thought it was a cursor note being properly filled. Now I have discovered what is causing empty cursor. Up to...

SQLite Error while compiling: CREATE TABLE IF NOT EXISTS entry (TEXT PRIMARY KEY, Test TEXT, )

android,sqlite,android-sqlite
This is my first attempt at using SQLite and I am receiving a conflict that is common, however, I have not been able to solve it on my own. Below is the cause of the issue. 03-10 17:43:21.747: E/AndroidRuntime(11225): Caused by: android.database.sqlite.SQLiteException: near ")": syntax error (code 1): , while...

Display data from sqlite-database and XML file in a TextView

android,android-intent,android-sqlite
I want to insert new rows in my table from a XML resource. I want to print dynamically buttons in first activity, the number of buttons depends from how many rows are in table. For example: TABLE_NAME = "languages" row1: LANGUAGE_NAME = "english", LANGUAGE_DESCRIPTION = "Some words in english" row2:...

int android.database.Cursor.getCount()' on a null object reference

java,android,sqlite,android-sqlite,android-cursorloader
got null poiner exception at cursor.getCount(); while doing ListView using cursor loader adapter class as below public class FriendsListCursorAdapter extends CursorAdapter { private Cursor cursor; final VROPreferenceManager preferenceManager = new VROPreferenceManager(); Context con; public FriendsListCursorAdapter(Context context, Cursor c, boolean b) { super(context,c,true); cursor = c; con=context; } public void addItems(Cursor...

SQLite PRIMARY key AutoIncrement doesn't work

android,sqlite,android-sqlite,auto-increment
I'm trying to a have a table with an auto incremented primary key. The SQL query for table creation is included. Problem is the auto-increment does not work. Meaning when I insert a row with NULL as the value of conversation_id it just inserts null. I have this problem on...

SQL query is returning one result less than expected

android,android-sqlite
my query keeps returning one result less than expected. Initialy I had 6 rows that needed to be returned, it kept returning only 5, I decided to add another one and now it is returning 6 instead of 7, It is always the last one. I tested the same query...

Android, database query selection argument of date

android,android-sqlite
Say I am accessing SMS database of Android: Uri uri = Uri.parse("content://sms/"); ContentResolver contentResolver = getContentResolver(); String[] projection = {"_id", "date"}; Cursor cursor = contentResolver.query(uri, projection, null, null, null); I want to select the rows which have "date" larger than a reference date. I know I need to use selection...

Return One value if more than one Exsist

android,database,sqlite,android-sqlite
if i have same values in a column and i want to return only one instead of all of them what would be a method. ArrayList<String> getAllNotes() { Cursor cursor; mDbHelper = mSqliteHelper.getWritableDatabase(); String query = "SELECT * FROM " + SqliteHelpers.TABLE_NAME; cursor = mDbHelper.rawQuery(query, null); ArrayList<String> arrayList = new...

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...

Moving android sql lite cursor forward

android,android-sqlite,cursors
I have a Sql lite table in my application. I want to add a cursor to parse the table such that it moves ahead from the current position. Main idea is to update all next rows and not previous one. can anyone give me a example cursor to do so...

android sqlite query with offset doesn't return desired rows

java,android,sqlite,sqlite3,android-sqlite
I'm using the following code to get a list of notifications (total rows are 21): List<Notification> list = new ArrayList<Notification>(); Cursor c = _db.query(TABLE_NAME, COL_ALL, null, null, null, null, order, get_limitStr(offset)); if(c != null && c.moveToFirst()) { while(!c.isAfterLast()) { Notification model = cursorToModel(c); if(model != null) { list.add(model); } c.moveToNext();...

when i tried to insert a row to database ,“table timeline has no column named source” occured"

java,android,android-sqlite
I did have a column named source.I had no ideas where i was wrong. I constructed table time at onCreate method. public class DbHelper1 extends SQLiteOpenHelper { static final String TAG = "DbHelper1"; static final String DB_NAME = "timeline.db"; static final int DB_VERSION = 1; static final String TABLE =...

Android App Crashes on Startup: SQLite NullPointerException in ContactsFragment

android,sqlite,android-fragments,android-activity,android-sqlite
I'm working on integrating a database to save and store basic contact information to be retrieved at a later time. However, my app is now crashing on startup so I cannot even verify if the table is being created, etc. 05-05 16:39:50.671 11631-11631/treehouse.greenlight E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: treehouse.greenlight, PID:...

Displaying data fetched from database in a Button in android

android-sqlite
I know how to fetch data from sqlite database and display it in a listview. But i want to know how to change the properties of a button according to data fetched from database like color,text etc. I searched a lot but could not find any relevant answer. Is it...

Cannot resolve symbol getReadableDatabse in Android Studio

android,sqlite,android-studio,android-sqlite
I can't seem to make this work. I am copying a youtube video tutorial about SQLite database in android studio and I encountered this error. Can someone please help? Thanks! public class DataListActivity extends ActionBarActivity { ListView listView; SQLiteDatabase sqLiteDatabase; UserDBHelper userDBHelper; Cursor cursor; ListDataAdapter listDataAdapter; @Override protected void...

Android Sqlite table column foreign keys?

android,android-sqlite
I am creating a fairly simple sqlite db for my android project. It has been a long time since i have written msql commands, let alone sqlite. To keep this question simple, lets just say i have two tables. One table for dogs and another for owners. In dogs there...

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...

OutOfMemoryError : no stack available

android,android-sqlite
I use an SQLite database to store data in my app. Here's a sample of how i access data on an asynctask : ArrayList < Data > allMessages = new ArrayList<>(); String query = "SELECT * FROM .........."; SQLiteDatabase db = this.getWritableDatabase(); Cursor c = db.rawQuery(query, new String[]{username}); try {...

Can on-device sqlite database of a mobile app be updated without updating the the app at the app store?

android,sqlite,mobile,android-sqlite
I am not an app programmer. I am planning an online e-commerce marketplace app and will be outsourcing the job. I have some programming knowledge and have few questions regarding the design of the app. I want the app to be fast. so I am willing to store the information...

SQLiteDatabase Cursor empty only on Android 5.0+ devices

android,android-sqlite,android-cursor
The application has a SearchView which fetches suggestions from a specific database table. Everything worked without any errors until Android 5.0 appeared. As of then, when the SQLiteQueryBuilder queries the database to fill the Cursor object, the return is empty cursor. Not NULL, but empty. On other platforms, I can...

select data according to Row in Sqlite

android,database,sqlite,android-sqlite
image i want to get the whole row i am using this code to get my desired data but its giving me null pointer exception at temp_address1 here is the code as in mentioned image i want to get the whole row matching phone number. how can i achive that...

Android SQLiteException syntax error code 1

android,syntax,android-sqlite
I made database in application, The code is giving error syntax (code 1) table exception. I read almost all questions about this exception, did all what it was said. but still it doesn't work. I couldn't find what the problem is. is there any one who can help me? My...

android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0 cursor

android,android-sqlite
I am getting the following error: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0. From this code: public Lirik getLirik(String id){ SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_MUPUH, new String[] { KEY_ID, JUDUL, KEY_MUPUH }, KEY_ID + "=?", new String[] { String.valueOf(id) }, null, null, null); if (cursor...

Passing parameter in Sql IN statement

sql,android-sqlite
How can I pass a parameter in the IN SQL statement ? cursor = readableDb.rawQuery("SELECT * FROM User where User.objectId NOT IN (@Par)", new String{"ID"} ); Is it the correct way to do it ?...

How to retrieving specific records from SQlite (Need Query)

android,sqlite,sqlite3,android-sqlite
I am working on apps in which i need retrieve specific records from one position to another. i have table Track_Detail having 20 records. How to retrieved records from 1 to 10 in one list and 11 to 20 in another list. here my source code: retrieve record from Track...

Android MMS database, select rows by date from a mystery column

android,sql,sqlite,android-sqlite
I am accessing Android MMS database to get the date of MMS message: Uri mmsUri = Uri.parse("content://mms/"); ContentResolver contentResolver = getContentResolver(); String[] projection = {"_id", "date"}; Cursor cursor = contentResolver.query(mmsUri, projection, null, null, null); long dateVal = cursor.getLong(cursor.getColumnIndex("date")); //This date is always 1970 Date mmsDate = new Date(dateVal); But the...

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....

SQLiteException near “<” while delete query

android,sqlite,delete,android-sqlite,where-clause
I am trying to delete a few rows from my SQLite database like this: dbUtilsObj.delete(EngineUtiReport.TABLE_NAME, EngineUtiReport.Columns.KEY_ENGINE_UTI_UNIX_TIME + DBUtils.IS_LESS_THAN, new String[] { String.valueOf(nDaysOldUnixTime) }); In the above code nDayOldTimeInMills = 1429963811949 and DBUtils.IS_LESS_THAN = " < ". But I am getting this syntax error exception and I just can't figure out...

Database choice for creating two connected tables?

database,database-design,android-sqlite
I have to database tables "Courses" and "Students". Courses table has columns ("_id", "course_name", "course_number"). Student table has columns ("student_name", "student_number", "course_number"). I've created Courses table, but i have problem with creating Students table. Two classes may have same student, so same student row will exist twice with different "course_number"s...

Is this Android SQL statement vulnerable to SQL injection?

android,android-sqlite
Is the query() method provided by SQLiteDatabase class safe to use without worrying about SQL injections? db.query(TABLE,cols,COL_ID + " = '" + id + "' AND " + COL_FROM + " = '" + from + "'",null,null,null,null); The id and from variables are completely unescaped. Or is the following the...

performFiltering() sql exception while filtering android.

android,listview,android-listview,android-sqlite
I am trying to filter SimpleCursorAdapter ListView But I am getting sql exception in filtering. I am trying to find those contacts who's name start's with user's entered text. String selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1"; cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, selection, null, null); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) {...

How to display a specific row in my database through another activity?

java,android,android-activity,row,android-sqlite
I wanted to display a specific row in my table. I have two Activities the first activity is to input the ID passed to the 2nd Activity which is going to display the row in my table based on the ID that I inputed. Hope you can help with my...

Accessing Android Content Provider inside Webview

html5,android-webview,android-sqlite,android-contentprovider
In Android. How do you access Content Provider inside your webview. It is showing content uri as not defined google.visualization.Query(CONTENT_URI, opt_options); ...

How to store SMS message to SQLite Database?

android,sms,broadcastreceiver,android-sqlite
I want to store the messages into SQLite database when they receive. I know I have to use BroadcastReceiver to do this. But I don't know how to do this. Is it possible to store incoming sms into database when onReceive() is called? Please help me.

How thread safe is EnableWriteAheadLogging in the context of real usage and SQLite documentation?

android,sqlite,android-sqlite
The android documentation describes "EnableWriteAheadLogging" over here: http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#enableWriteAheadLogging() "This method enables parallel execution of queries from multiple threads on the same database" However, according to the SQLite documentation: https://www.sqlite.org/threadsafe.html there are two kinds of multithreading for SQLite: "Serialized" and "Mulit-thread". Which one is used when using "EnableWriteAheadLogging"? In addition, if...

Cannot find the SQLite db file on my device

android,database,sqlite,sqlite3,android-sqlite
I created a database in the following code. public final class MembershipDatabaseHelper extends SQLiteOpenHelper { private static final String DB_NAME = "members.db"; private static final String DB_TABLE = "members"; private static final int DB_VERSION = 1; private static final String COLUMN_ID = "_id"; private static final String COLUMN_EMAIL = "email";...

Why does SQLite give Cannot create instead of trigger on table

triggers,sqlite3,android-sqlite
With this table create table FOLDER ( _ID integer primary key autoincrement, NAME text not null, PARENT integer not null, DELETED integer, constraint VALUEOF_folder_deleted check (DELETED == 1 or DELETED isnull) on conflict abort, unique (NAME, PARENT) on conflict abort ); I wanted to replace an insert where the NAME...

Put values in the same column

android,android-sqlite
I have a problem when I try to put values in a column, this is my code: scelta.put(Codice.DATI_NOME_DIETA, "Scarsdale"); scelta.put(Codice.DATI_NOME_DIETA, "Dieta Atkins"); scelta.put(Codice.DATI_NOME_DIETA, "Dieta dissociata"); scelta.put(Codice.DATI_NOME_DIETA, "Weight Watchers"); scelta.put(Codice.DATI_NOME_DIETA, "Dieta Zona"); scelta.put(Codice.DATI_NOME_DIETA, "La dieta Dukan"); scelta.put(Codice.DATI_NOME_DIETA, "Cronodieta"); db.insert(Codice.TABLE_SCELTA, null, scelta); But when I print the table I see only the...

Getting android Sqlite syntax error running in api 14

android,android-activity,android-sqlite,android-adapter,simplecursoradapter
I have sequence of database adapter, which dumps default values in to the tables. It works fine on the devices running on API level 19 to 21. When I tried it in API 14. I'm getting the syntax error. I/SqliteDatabaseCpp﹕ sqlite returned: error code = 1, msg = near ",":...

How to send scheduled SMS messages in Android?

android,sms,android-sqlite,scheduled-tasks
I have to create an app which has some Mobile numbers in its database. It has to send SMS to everyone one of the number in the database at 12:00 AM everyday. I know how to add the numbers in database. But I don't know how to send scheduled messages...

SQLite in android : blank row being entered Even after nullcolumnhack is set to null. Why?

android,android-sqlite
So this is my dbAdapter class which handles data entry in database. Initialized this class object in custom dialogfragment. And onclick event of button of the custom dialog fragment i am inserting a row. if i leave the edittext empty and then do onclick , it INSERTS a row. which...

Select data that is ordered from sqlite

android,android-sqlite
I am trying to to get data with it ordered by a column but it is not working. Any idea on why? public ArrayList<HashMap<String, String>> getMonthData(String month,String year, String name){ ArrayList<HashMap<String,String>> activityArrayList = new ArrayList<HashMap<String,String>>(); String selectQuery = "SELECT * FROM activity WHERE year='"+year+"' AND month='"+month+"' AND name=? ORDER BY...

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;...

sqlite: How can results be made unique according to a column

sqlite,android-sqlite
Currently, the following sqlite query returns 45 records. I know that only 4 albums exist. How can the query be made to return only those records that are unique to albumTable.album. Pseudo Code: where albumTable.album is UNIQUE query = new StringBuilder(); query.append("select albumTable.album, artistTable.artist, songTable.filepath "); query.append("from albumTable "); query.append("inner...

sqlite syntax error when updating with string value Android

android,android-sqlite
public class Profile implements Parcelable { public final static String ACCOUNTS_TABLE_NAME = "accounts"; public final static String FIELD_DISPLAY_NAME = "displayname"; public final static String FIELD_IP = "ipaddress"; } String f1 = "planet"; String ip = "udp:85.59.123.78:289"; My update query is like below db.execSQL("UPDATE " + Profile.ACCOUNTS_TABLE_NAME + " SET "...

sqlite database no colums

database,sqlite,android-sqlite
how are you ? im trying to make a sqlite data base there is my code public class SQliteHelper extends SQLiteOpenHelper { public static final int DATABASE_VERSION = 1; public static final String DATABASE_NAME = "moneyDB"; public static final String TABLE_MONEY = "money", KEY_DATE = "date", KEY_VALUE = "value", KEY_WHY...

Cannot create an object for SQLiteOpenHelper from AsyncTask thread?

java,android,android-asynctask,android-sqlite
I have to create an object for SQLiteOpenHelper from AsyncTask thread. If I use this as the Context parameter, I'm getting an error - it cannot be applied. Here are my classes : MySQLiteHelper.java public class MySQLiteHelper extends SQLiteOpenHelper { public MySQLiteHelper(Context context) { // the constructor takes Context as...

SQLiteDatabase.rawQuery(java.lang.String, java.lang.String[])' on a null object reference

java,android,sqlite,sqlite3,android-sqlite
When accessing the database a NullPointerException is thrown. Here is the code that creates the db: public class DatabaseHelper extends SQLiteOpenHelper { public static final String KEY_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS {0} ({1})"; public static final String KEY_DROP_TABLE = "DROP TABLE IF EXISTS {0}"; private Context context; Activity...

How to store overtime location info in Android

android,ruby-on-rails,android-sqlite
I'm working on an app that collects user's location data overtime (like every 5 seconds while driving it should update their location). Ultimately I want these periodic location updates to sync up to my Rails server. I'm wondering what the best way is to store/sync them up to my server....

Can anyone explain me why is this KEY_ID needed in SQLite Database?

java,android,mysql,android-sqlite
I'm following this tutorial. onCreate(): What does that INTEGER PRIMARY KEY AUTOINCREMENT mean? I can infer that it is the primarykey and it is auto incremented. public void onCreate(SQLiteDatabase db) { // SQL statement to create book table String CREATE_BOOK_TABLE = "CREATE TABLE books ( " + "id INTEGER PRIMARY...

Android SQLiteDatabase Insert Syntax Error

syntax-error,android-sqlite,sql-insert
I've searched around and found people with similar issues, yet not quite the same. I'm receiving an SQLite syntax error, but I cannot locate the bad syntax. Please help! I created an SQLite Database in DatabaseAdapter.java, seen here: static class DatabaseHelper extends SQLiteOpenHelper{ private static final String DATABASE_NAME = "mealdatabase";...

SQLite Android - geting month

android,sqlite,android-sqlite
i´m trying to get all the records within the month. my date is stored as a TEXT(tryed DATE) and a string in android my method for get the current date: private String getDateTime() { SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss", Locale.getDefault()); Date date = new Date(); return dateFormat.format(date); }...

Get a new array with column values from two different arrays in android

java,android,arrays,sqlite,android-sqlite
Hi I have two array values loncountries[index] = [80.2116001, 80.173399] latcountries[index] = [13.042699, 13.0409047] Now I want them in a new Array like loncountries[index] = [13.042699,80.2116001] latcountries[index] = [13.0409047,80.173399] Just the first columns as a new Array. Also I am fetcihg it from Sqlite Database and attaching the code below....

NOT refresh after deleting the ListView array list item android

android,android-listview,android-sqlite,android-checkbox
I am trying to implement ListView with Delete functionality to delete item from the ListView. I am successful to delete but failed to refresh the ListView after deletion of an item from the ArrayList. Actually, Click on ListView, i am displaying AlertBox for "Delete" and "Cancel" action, on clicking "Delete",...

Android SQLite issue: 'Table […] has no column named' error

android,sqlite,android-studio,android-sqlite
I keep getting error that a column in my table cannot be found. Cannot figure out why this is happening. The column names appear to be spelled correctly. I'm getting this error : 06-11 21:27:02.701 3703-3703/com.example.luca.contatti E/SQLiteLog﹕ (1) table Contatti has no column named imageUri This is my DatabaseHandler page:...

Android: Why values from BD are not being written in TextViews?

android,android-sqlite
This is may be a basic problem but I can't find the solution to it. I'm doing a query to my BD to get a value(DESPESA), and the value is correctly returned (I've proved it with Log.d) but it isn't, then, printed on the Activity and on the TextView. Can...

Show error if data cannot be inserted

android,database,android-sqlite
I need to handle an error when non-unique data is inserted into the database. I have this code: try { handler.addBookmark(new BookmarkModel(idBrand, brand, desc, types, detail, image)); Toast.makeText(this, "Success", Toast.LENGTH_LONG).show(); }catch (SQLiteException e){ e.printStackTrace(); Toast.makeText(this, "Failed", Toast.LENGTH_LONG).show(); } I insert like this: public long addBookmark(BookmarkModel bookmark) { SQLiteDatabase db =...

can anyone tell me how to store geocoder address in android database using android studio?

android,android-studio,android-sqlite
I am able to see the address(for on click listener) fetching from the GeoCoder code and i am able to display in log file but i am not able to store that address in my local DataBase. can any one please help me in this issue. thanks in advance. package...

RuntimeException: Unable to resume activity

android,android-sqlite,android-runtime
I am newbie in Android and trying to create a database with to tables , but when i fire my project, i got the following errors in logcat : 05-04 11:21:29.678 1634-1634/com.example.keco.myapplication E/SQLiteLog﹕ (1) near "TABLEstudents": syntax error 05-04 11:21:29.680 1634-1634/com.example.keco.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.keco.myapplication, PID: 1634 java.lang.RuntimeException:...

SQLite android - Select records within the last year

android-sqlite
i'm getting the sum() of the records of one month in this year.. here it is the method to get the month , but how can i get only the month of this year and not from the last year? public Cursor calculate(String month){ return db.rawQuery("Select " + "sum(" +...

using Loader with a Fragment/Activity with UI widgets triggering updates to the loaders content

android,android-activity,android-sqlite,android-loadermanager,android-loader
I'm using for a while the Loaders API's. I found it great solution and most elegant design to solve the generic problem of most apps: displaying "processed" dynamic content with minimum interference to the Fragment/Activity - the responsibility of loading the data and all the logic behind that is encapsulated...

How to know what is behind SQLiteCursor's address seen during debugging?

android,android-sqlite,android-cursor
I am debugging an application and when the Cursor retrieves a pointer from the database, I see something like this How can I know what means the value behind @? How can I bind this address to the database value behind it? Why do I need this? The app is...

Getting ordered subset of records

sql,sqlite,android-sqlite
I have table which basically describes a bus route. The table includes all the stops of a particular route. This SQLFiddle shows an example. The data shows the flow in one direction, but a route can also be in the other direction. I need to get a subset of this...

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...

Get data between current date to last month date from SQLite database

android,date,android-sqlite
I need to get data in between current date to last month (means last 30 days) from SQlite. Here is code to get list of all data but i get nothing from this. public List<Birthday> getWeekBirthdays() { List<Birthday> birthdays = new ArrayList<Birthday>(); SQLiteDatabase db = this.getReadableDatabase(); Calendar theEnd = Calendar.getInstance();...

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...

Android sqlite Query with AND [closed]

android,android-sqlite
I wanted to ask how do you make a query like : select * from table where id = 1 AND year = 1999 with the command query of sqlite in Android? Thanks in advance...

What's practical purpose of cursorLoader?

android,android-sqlite,android-cursor,android-cursorloader
I saw some articles about cursorLoader like this, but i still don't understand the particular purpose of using it. I developed apps with sql and cursor retrieving. The point is it was very fast. I queried and parsed cursor with >500 record and 8 columns by a few millisecond. So...

NullPointerException at getWriteableDatabase

android,sqlite,nullpointerexception,android-sqlite,getwritabledatabase
I'm trying to create simple database app using SQLite, but it looks like I can't manage to get reference to the created database. I keep getting NullPointerException, which points to getWriteableDatabase command. Database class: public class DatabaseHelper extends SQLiteOpenHelper { public SQLiteDatabase db; public static final String DATABASE_NAME = "user_database.db";...

Getting SQLiteException while calling getReadableDatabase

android,android-sqlite
Above code is the part of intent service where I am accessing GinisTable class which is actually a DBHelper class. protected void onHandleIntent(Intent intent) { if (intent != null) { DeviceInfoTable deviceInfoTable = new DeviceInfoTable(UploadGiniData.this); DeviceInfo deviceInfo = deviceInfoTable.getDeviceInfo(); String generatedDeviceInfo = deviceInfo.getGeneratedDeviceId(); GinisTable ginisTable = new GinisTable(UploadGiniData.this); List<GiniInfo> giniInfoList...

Create table sqlite syntax error

android,android-sqlite
Caused by: android.database.sqlite.SQLiteException: near "case": syntax error (code 1):, while compiling At CREATE TABLE case ( case_id TEXT PRIMARY KEY, case_body TEXT, case_title TEXT, case_published INTEGER, case_thumbnil TEXT,case_type TEXT ); Can any one please tell me what is the problem, I am testing this on Android 5.0.2 I have...

syntax error in composite primary key android

android,android-sqlite
String CREATE_FINANCE_TABLE = "CREATE TABLE " + TABLE_FINANCE + "(" + FIN_USERID + " INTEGER PRIMARY KEY" + " REFERENCES " + TABLE_USER + "("+ USER_ID +")," + FIN_CARID + " INTEGER," + FIN_TOTALPRICE + " REAL, " + FIN_DOWNPAYMENT + " REAL," + FIN_BALANCE + " REAL, " +...