Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Java Persistence with Spring Data and Hibernate
this week in the
Spring
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Tim Cooke
Paul Clapham
Liutauras Vilda
Sheriffs:
Junilu Lacar
Rob Spoor
Jeanne Boyarsky
Saloon Keepers:
Stephan van Hulst
Carey Brown
Tim Holloway
Piet Souris
Bartenders:
Forum:
Android
it doesn't delete after i called delete method
shawn peter
Ranch Hand
Posts: 1325
1
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
this is my main class
package com.connection.phonedetails; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.TelephonyManager; import android.widget.Toast; public class TestDB extends Activity { private static final int REQUEST_CODE = 10; private static String TYPE = "NONE"; TelephonyManager telephonyManager; DatabaseHandler db; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.alert); telephonyManager = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)); try { db = new DatabaseHandler(this); SimDetails data = db.getContact(telephonyManager .getSimSerialNumber()); db.deleteContact(data); SimDetails test = db.getContact(telephonyManager .getSimSerialNumber()); db.close(); } catch (Exception e) { e.printStackTrace(); } } }
this is db class
public SimDetails getContact(String id) { SimDetails product = new SimDetails(); try { // SimDetails product = new SimDetails(); String query = "Select * FROM " + TABLE_SIM + " WHERE " + KEY_SIM_NO + " = \"" + id + "\""; SQLiteDatabase db = this.getReadableDatabase(); /* * String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_SIM + "(" * + KEY_NAME + " TEXT," + KEY_SIM_NO + " TEXT PRIMARY KEY," + * KEY_SIM_TYPE + " TEXT" + ")"; db.execSQL(CREATE_CONTACTS_TABLE); */ // db.execSQL("DROP TABLE IF EXISTS " + TABLE_SIM); Cursor cursor = db.rawQuery(query, null); if (cursor.moveToFirst()) { cursor.moveToFirst(); product.set_name((cursor.getString(0))); product.set_serial_number((cursor.getString(1))); product.set_sim_type((cursor.getString(2))); cursor.close(); } else { // product.set_name(global); } } catch (Exception e) { product.set_name(global); e.printStackTrace(); } return product; } // Deleting single contact public void deleteContact(SimDetails contact) { try { String query = "Select * FROM " + TABLE_SIM + " WHERE " + KEY_SIM_NO + " = \"" + contact.get_serial_number() + "\""; SQLiteDatabase db = this.getWritableDatabase(); db.delete(TABLE_SIM, KEY_SIM_NO + " = " + contact.get_serial_number(), null); db.close(); } catch (Exception e) { e.printStackTrace(); } }
after i called the delete method in main cactivity also ,record is still in db.The variable
test
has value as data.please help.
shawn peter
Ranch Hand
Posts: 1325
1
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I change the delete to below.Then it returns valo 0 from delete.
int s=db.delete(TABLE_SIM,KEY_SIM_NO + " = " + contact.get_serial_number(), null);
expectation is the root of all heartache - shakespeare. tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
put in LIST Sample Data to debug, also how view SQLITE DB Data from Eclipse IDE for debug purposes
Problem developing app
Not able to Insert data in SQLite
activity doesn't wait untill alertdialog completes
why it doesn't create data base table
More...