在Android中永久删除SQLite数据库

时间:2014-06-13 07:44:35

标签: android sqlite

我想删除现有的SQLite数据库。我已经尝试过每个查询删除现有数据库,但它没有从android.Below中的文件浏览器中删除是我的数据库代码告诉我我错在哪里。

Password.Db

package com.sunmobileappnow.mobileappnow;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;
import android.widget.EditText;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class PasswordDB

{
    EditText edittext;
     TextView tv;
    private static final  String DATABASE_NAME = "DGC.db";
    private static final int DATABASE_VERSION = 1;
    static final String TABLE_NAME = "Drivers";
    public static Context context;
    public static SQLiteDatabase db;

    private SQLiteStatement insertStmt;

   private static final String INSERT = "insert into " + TABLE_NAME + " (mfname,msname,mun,mstreet,msuburb,mstate,mpostcode,mlicense,mid,mmobile,memail,mimagelicense,mauthcard,mpic) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    protected static final String enternpw = null;
    public PasswordDB(Context context) {
    PasswordDB.context = context;
    OpenHelper openHelper = new OpenHelper(PasswordDB.context);
    PasswordDB.db = openHelper.getWritableDatabase();
    this.insertStmt = PasswordDB.db.compileStatement(INSERT);
    }
public long insert(String mfname,String msname,String mun,String mstreet,String msuburb,String mstate,String mpostcode,String mlicense,String mid,String mmobile,String memail,byte[] mimagelicense,byte[] mauthcard,byte[] mpic ) {
        this.insertStmt.bindString(1, mfname);
        this.insertStmt.bindString(2, msname);
        this.insertStmt.bindString(3, mun);
        this.insertStmt.bindString(4, mstreet);
        this.insertStmt.bindString(5, msuburb);
        this.insertStmt.bindString(6, mstate);
     // this.insertStmt.bindString(7, mpassword);
        this.insertStmt.bindString(7, mpostcode);
        this.insertStmt.bindString(8, mlicense);
        this.insertStmt.bindString(9, mid);
        this.insertStmt.bindString(10, mmobile);
        this.insertStmt.bindString(11, memail);
        this.insertStmt.bindBlob(12, mimagelicense);
        this.insertStmt.bindBlob(13, mauthcard);
        this.insertStmt.bindBlob(14, mpic);
        return this.insertStmt.executeInsert();
    }


  public void deleteAll() {
    db.delete(TABLE_NAME, null, null);
    }
    public void dropTable() {
          db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        }

    public List<String[]> selectAll()
    {
    List<String[]> list = new ArrayList<String[]>();
    Cursor cursor = db.query(TABLE_NAME, new String[] { "first_name", "Surname","unit_no","Street_name","Suburb","State"," post_code","driving_lic","authority_id","mobile_no","Email","password","license_pic","audit_card_pic","face_pic"," date_of_creation","status","login_token","device_token","latitude", "longitude" }, null, null, null, null, "mEmail asc");
   // Cursor cursor = db.query(TABLE_NAME, new String[] { "id","mfname","msname","mun","mstreet","msuburb","mstate","mpassword","mconfirm_password","mpostcode","mlicense","mid","mmobile","memail","mimagelicense","mauthcard","mpic" }, null, null, null, null, "memail asc");        

    int x=0;
    if (cursor.moveToFirst()) {
       do {
        String[] b1=new String[]{cursor.getString(0),cursor.getString(1),cursor.getString(2),
                cursor.getString(3),cursor.getString(4),cursor.getString(5),
                cursor.getString(6),cursor.getString(7),cursor.getString(8),cursor.getString(9),cursor.getString(10),cursor.getString(11),cursor.getString(12),cursor.getString(13),cursor.getString(14),cursor.getString(15)};
        list.add(b1);
        x=x+1;
       } while (cursor.moveToNext());
    }
    if (cursor != null && !cursor.isClosed()) {
       cursor.close();
    }
    cursor.close();
    return list;
   }


   public void delete(int rowId) {
    db.delete(TABLE_NAME, null, null);
   }

   private static class OpenHelper extends SQLiteOpenHelper {
    OpenHelper(Context context) {
         super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE " + TABLE_NAME + " (id INTEGER PRIMARY KEY,first_name TEXT,Surname TEXT,unit_no TEXT,Street_name TEXT,Suburb TEXT,state TEXT,pickup_time TEXT,date_of_creation TEXT, destination TEXT, group TEXT,fare TEXT, latitude TEXT, longitude TEXT,city TEXT,license_pic BLOB,audit_card_pic BLOB,face_pic BLOB)"); 
        // db.execSQL("CREATE TABLE " + TABLE_NAME + " (id INTEGER PRIMARY KEY, mfname TEXT, msname TEXT,mun TEXT,mstreet TEXT,msuburb TEXT,mstate TEXT,mpassword TEXT,mconfirm_password TEXT,mpostcode TEXT,mlicense TEXT,mid TEXT,mmobile TEXT,memail TEXT,mimagelicense BLOB,mauthcard BLOB,mpic BLOB)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
        {
         db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
         onCreate(db);
    }
   }


public Cursor rawQuery(String selectQuery, Object object) {
    // TODO Auto-generated method stub
    return null;
}
public static PasswordDB getDBAdapterInstance(ViewData viewPassword) {
    // TODO Auto-generated method stub
    return null;
}
public Object getenternpw() {
    // TODO Auto-generated method stub
    return null;
}
public static Cursor getSinlgeEntry() {
    // TODO Auto-generated method stub

    Cursor cur =db.rawQuery("SELECT * FROM "+  TABLE_NAME, null);
    // colName1+"='"+name+"'" ->  wherclause
    System.out.println("Record count are "+cur.getCount());
    return cur; 

}

public static void close() {
    // TODO Auto-generated method stub

}
public PasswordDB open() {
    // TODO Auto-generated method stub
    return null;
}

public void delete(String tableName, Object object, Object object2) {
    // TODO Auto-generated method stub

}

public Cursor query(String tableName, String[] strings, Object object,
        Object object2, Object object3, Object object4, String string) {
    // TODO Auto-generated method stub
    return null;
}

public void insert(String first_name, String surname, String unit_no,
        String street_name, String suburb, String state, String post_code,
        String driving_lic, String authority_id, String mobile_no,
        String email, String password, String license_pic,
        String audit_card_pic, String face_pic, String date_of_creation,
        String status, String device_token, String latitude, String longitude) {
    // TODO Auto-generated method stub

}

1 个答案:

答案 0 :(得分:0)