android-sqlite

How to delete a particular row from SQLite database

纵饮孤独 提交于 2019-12-25 16:43:18
问题 I have created a list view. On button click the data is added in list and also stored in an SQLite database. I have also added the image on the right-hand side of list, on click of which a particular row data is deleted, but I also want to delete data from SQLite. How could I do this? Main Activity.Java public class MainActivity extends Activity { EditText editText; Button Button,Button1; ListView listView; ArrayList<String> listItems; BaseAdapter adapter; private DataBaseHandler mHelper;

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

杀马特。学长 韩版系。学妹 提交于 2019-12-25 16:36:48
问题 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 C; private static final int CURRENT_DB_VERSION = 1; private static final String DB_NAME = "vrochat.db"; SQLiteDatabase Db1; public DatabaseHelper

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

早过忘川 提交于 2019-12-25 16:36:38
问题 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 C; private static final int CURRENT_DB_VERSION = 1; private static final String DB_NAME = "vrochat.db"; SQLiteDatabase Db1; public DatabaseHelper

How to pull data from database and view them as a ListView

一个人想着一个人 提交于 2019-12-25 14:00:39
问题 I am using a custom list adapter for my ListView. My each list item has 4 items. which are come from a listArray. Here is the code which pull the list items from List Array. import android.app.Fragment; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ListView; import com.rupomkhondaker.sonalibank.adapter

Check if column string in database is a substring of a query in sqlite

早过忘川 提交于 2019-12-25 11:31:10
问题 the current Sqlite syntax can check if a query is a substring of a column string. and I can do a hack to add a % behind the ? described in https://stackoverflow.com/a/5752671/908821 final String whereClause = DbHelper.COLUMN_URL + " LIKE ? " ; is there a syntax where i can do the opposite? I want to check if the column string is a substring of a query. The following code does not seem to work. final String whereClause = "? LIKE " + DbHelper.COLUMN_URL ; The following are the rest of my codes:

Android - Sqlite - Detect if new version not found

不问归期 提交于 2019-12-25 09:41:27
问题 Updated: Bref: The answer of Kuffs is simple and correct. The answer of MikeT is a interesting approach. Old version: I'm working on an android app. I need to know if there are a new sql version or not. If my db is up to date, I will trigger an async action. But how can I trigger my async action? Currently, I have my own flag onNewVersion who is set to true in onUpgrade() . Then I do the check in onOpen() . Are there any other methods? @override onUpgrade(...) { onNewVersion = true; ... }

Insert over 6000 records in sqlite - android?

泄露秘密 提交于 2019-12-25 09:15:24
问题 I get a lot of records from webService (over 5000) and then I need to Insert them in my sqlite but when I Insert them in my sqlite get a long time for Insert and often get me crash. What can I do? My insert item is same below: public long InsertData(Marketing_Points_B MP, Context context) { DBS db = new DBS(context); PACKAGE_NAME = context.getApplicationContext().getPackageName(); db.GetPackageName(PACKAGE_NAME); db.CreateFile(); try { db.CreateandOpenDataBase(); } catch (IOException e) { e

Error compiling insert into: No column named ID

痞子三分冷 提交于 2019-12-25 08:57:43
问题 Been testing some answers found but still no effect. What am I missing? Please see below. String createTableCommand = "CREATE TABLE " + TABLE_NAME + "(" + COL_USER_ID +" INTEGER PRIMARY KEY," + COL_USER_FULL_NAME + " TEXT NOT NULL," + COL_USER_PASSWORD + " TEXT NOT NULL)"; @Override public void onCreate(SQLiteDatabase db) { db.execSQL(createTableCommand); } public void insertUsers(User user){ SQLiteDatabase db = this.getReadableDatabase(); ContentValues values = new ContentValues(); values

Ormlite DatabaseConfigUtil.java generating raw empty file and database fields are not added

空扰寡人 提交于 2019-12-25 07:35:00
问题 I'm using Eclipse Helios on Win 7 platform. I have this Dao class package com.example.hello; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; @DatabaseTable(tableName = "accounts") public class Account { // for QueryBuilder to be able to find the fields public static final String NAME_FIELD_NAME = "name"; public static final String PASSWORD_FIELD_NAME = "passwd"; @DatabaseField(generatedId = true) private int id; @DatabaseField(columnName = NAME_FIELD

Android - Cursor onMapReady (Markers)

本小妞迷上赌 提交于 2019-12-25 06:27:57
问题 I'm trying to "inflate" my content from SQLite into Markers but the solution I took of here it's not working, and it's not throwing any information on Log. I'm a bit new on this Marker stuff and SQLite My code inside the Fragment : SQLiteHelper dbHelper = new SQLiteHelper(getActivity()); pds = new ParksDataSource(dbHelper.db); parks = pds.getAllParks(); List<Marker> markersList = new ArrayList<Marker>(); int i = 0; Cursor cursor = db.rawQuery("SELECT * FROM " + SQLiteHelper.TABLE_PARKS, null)