uso este código:
public void deleteAll()
{
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("delete from "+ TABLE_NAME);
db.close();
}
puedes añadir clase DatabaseHandler, este es el código fuente completo:
public class DatabaseHandler extends SQLiteOpenHelper {
// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
public static final String DATABASE_NAME = "OffLineMessagesClient";
// Contacts table name
public static final String TABLE_NAME = "messages_client";
// Contacts Table Columns names
private static final String KEY_ENTITY_ID = "entity_id";
private static final String KEY_MESSAGE = "message";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_NAME + "("
+ KEY_ENTITY_ID + " INTEGER,"
+ KEY_MESSAGE + " TEXT"
+ ")";
db.execSQL(CREATE_CONTACTS_TABLE);
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
// Create tables again
onCreate(db);
}
public void deleteAll()
{
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("delete from "+ TABLE_NAME);
db.close();
}
}
El método delete devuelve un valor. ¿Qué valor estás obteniendo? –
¿Eliminar registros de la tabla mediante el trabajo compileStatement? –
Puede eliminar el 'database.sqlite' y volver a crear la estructura después. – ChristopheCVB