vendredi 8 janvier 2016

trouble with pre-existing sqllite .db file in android

I want to access the file that is saved in the SDcard, but android studio is throwing code 14 error, cannot open databse.

here is my database helper code...

class DataBaseHelper extends SQLiteOpenHelper {

//The Android's default system path of your application database.
//private static String DB_PATH = "/data/data/com.example.amit.sqtry/databases/";

private static String DB_NAME = "wep_data";

private SQLiteDatabase myDataBase;

private  Context myContext;

/**
 * Constructor
 * Takes and keeps a reference of the passed context in order to access to the application assets and resources.
 * @param context
 */
public String icons;
public DataBaseHelper(Context context) {

    super(context, DB_NAME, null, 1);
    try {

        this.myContext = context;

        File dbFile = new File( Environment.getExternalStorageDirectory(), "wep_data.db" );
        SQLiteDatabase mydatabase =SQLiteDatabase.openOrCreateDatabase(dbFile.getAbsolutePath(),null,null);;
        Cursor resultSet = mydatabase.rawQuery("select icon from wep", null);
        resultSet.moveToFirst();
        icons = resultSet.getString(1);
    } catch (Exception e) {
        Toast.makeText(context ,e.toString() , Toast.LENGTH_LONG).show();
    }
}

@Override
public void onCreate(SQLiteDatabase db) {

}

public String getIcons()
{
    return this.icons;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}

}

This is the main activity code. I want to set the value i got from the databse as text in textview.

basically what i want to do is get inputs from pre-existing sqlite database.

Aucun commentaire:

Enregistrer un commentaire