0

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

MByD
  • 135,866
  • 28
  • 264
  • 277
thathashd
  • 1,022
  • 4
  • 17
  • 49

1 Answers1

2

Refer to my post here:

Storing Lists to A Database, and Retrieving Them All Together : Android

One thing to mention is that in your utility class you could have a private SQLite Database Object, so that you could refer to the same database whenever you need to. If you need any further help with how to do this.. ask in the comments.

Community
  • 1
  • 1
JoxTraex
  • 13,423
  • 6
  • 32
  • 45
  • hello. Thank you for your attention but this is not quite the answer I seek, for my question. Thank you for your attention – thathashd May 05 '11 at 18:40