bom dia,
estou seguindo um tutorial um pouco antigo de android, nesse tutorial utiliza dois metodos
- mDb = mCtx.openDatabase(DB_NAME, null);
- mDb = mCtx.createDatabase(DB_NAME, DB_VERSION, 0, null);
esses metodos estao dando erro, fiz umas pesquisas e descobri um metodo "openOrCreateDatabase()"
achei uns exemplos mas nao consegui adaptar … mas queria que alguem me ajudasse a adaptar para meu codigo.
ESSE É MEU CODIGO ATUAL
public DbAdapter open() throws SQLException{
try{
mDb = mCtx.openDatabase(DB_NAME, null);
}catch (FileNotFoundException e){
try{
mDb = mCtx.createDatabase(DB_NAME, DB_VERSION, 0, null);
mDb.execSQL(DB_CREATE);
}catch (FileNotFoundException el){
el.printStackTrace();
throw new SQLException("nao pode conectar ao banco!");
}
}
return this;
}
public void close(){
mDb.close();
}
public long createExpense(String desc, float value){
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_DESCRIPTION, desc);
initialValues.put(KEY_VALUE, value);
return mDb.insert(DB_TABLE, null, initialValues);
}
ESSE É UM EXEMPLO QUE ACHEI COM O METODO “openOrCreateDatabase()”
public void InsereNovo(Empresa empresa) {
try {
db = openOrCreateDatabase(DB_NAME, SQLiteDatabase.CREATE_IF_NECESSARY, null);
ContentValues cv = new ContentValues();
cv.put("nome", empresa.getNome());
cv.put("data", empresa.getData());
db.insert(TABLE_NAME, null, cv);
db.close();
}
catch (SQLiteException se) {
Log.e(getClass().getSimpleName(), "Could not create or Open the database");
}
}
como posso adptar com o meu codigo???