I have a class in which I create the database. I want to do data manipulation in another class. I have the following code:
public class DBCreation
{
public static final String KEY_CODPROJECT = "codProject";
public static final String KEY_NOME = "nome";
private static final String TAG = "DBCreation";
private static final String DATABASE_NAME = "scrum_management.db";
private static final String DATABASE_TABLE = "project";
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_CREATE =
"create table project (codProject integer primary key autoincrement, "
+ "name text);";
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DBCreation(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS projecto");
onCreate(db);
}
}
public DBCreation open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}
public void close()
{
DBHelper.close();
}
}
Then I have a class to access the data.
public class DBAdapter extends DBCreation{
public DBAdapter(Context ctx) {
super(ctx);
// TODO Auto-generated constructor stub
}
//---insere um novo local na base de dados---
public long insertLocal(String descricao, String pais, String cidade,String categoria_desc)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_NOME, nome);
}
}
This is wrong. Can somebody help me how i can do the data manipulation in another class doing something like this?
Thanks