附加SQLite数据库的crud?

时间:2017-01-12 20:56:28

标签: android sqlite

从附加数据库填充ListView,但我正在尝试进行插入,更新和删除,但我不知道如何使用资产文件夹中的附加数据库执行此操作,尝试使用Class和GetView方法但没有什么工作,请看我的DBH。

public class DBC extends SQLiteOpenHelper {
       ;
       public static final String DBNAME = "MYDB.sqlite";
       public static final String DBLOCATION = "/data/data/developer.pmca/databases/";
       private Context mContext;
       private SQLiteDatabase mDatabase;


       public DBC(Context context, String name,
                  SQLiteDatabase.CursorFactory factory, int version) {
           super(context, DBNAME, null, 1);
           this.mContext = context;
       }

       @Override
       public void onCreate(SQLiteDatabase db) {

       }

       @Override
       public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

       }

       public void openDatabase() {
           String dbPath = mContext.getDatabasePath(DBNAME).getPath();
           if (mDatabase != null && mDatabase.isOpen()) {
               return;
           }
           mDatabase = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
       }

       public void closeDatabase() {
           if (mDatabase != null) {
               mDatabase.close();
           }
       }


       public List<FML> getListDataCliente() {
           FML FML = null;
           List<FML> FMLList = new ArrayList<>();
           openDatabase();
           Cursor cursor = mDatabase.rawQuery("SELECT distinct NamebA,TypeRamo,NumberPol,NumberCrt,NumberRc,Adress FROM MyTable group by NamebA,TypeRamo,NumberPol,NumberCrt,Adress ", null);
           cursor.moveToFirst();

           while (!cursor.isAfterLast()) {
               //
               FML = new FML(cursor.getString(0), cursor.getInt(1), cursor.getInt(2), cursor.getInt(3), cursor.getInt(4), cursor.getString(5));
               FMLList.add(FML);
               cursor.moveToNext();
           }
           cursor.close();
           closeDatabase();
           return FMLList;




       public boolean RB_Delete(String NRC) {
           boolean result = false;
           openDatabase();
           mDatabase.execSQL("DELETE  FROM MyTable Where NumberRC ="+NRC);
           closeDatabase();
           return result;

       }
   }

0 个答案:

没有答案