3
I have a table created by Sqlitestudio that when copied to the folder assets
in an app Eclipse doesn’t work.
In case my database class will only have a list( method which is what I need) because the database is already created with the table and data.
public class DatabaseHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "rtw";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public List<String> getAllLabels(){
List<String> list = new ArrayList<String>();
// Select All Query
String selectQuery = "SELECT * FROM regiao where uf = 'RS' " ;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);//selectQuery,selectedArguments
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
list.add(cursor.getString(1));//adding 2nd column data
} while (cursor.moveToNext());
}
// closing connection
cursor.close();
db.close();
// returning lables
return list;
}
How to solve the problem?
I tried by the emulator, In my data/data/package directory does not appear database, do I have to create these database? but I’ve already created I just want to copy
– War Lock
What it does is basically this: Checks whether db in the directory /data/data/SEUPACKAGE/Databases already exists. If it doesn’t exist it copies the bytes of the Assets folder where it should. There are 2 classes, one utility (with copy and check methods, etc.) and the other is the example of using this utility class...
– Ernani Joppert