开发者

What are the parameters for constructor of class cl_DBHandler which extends SQLiteOpenHelper in android?

开发者 https://www.devze.com 2023-04-12 16:27 出处:网络
i have created class cl_DBHandlerwhich extendsSQLiteOpenHelper. and i have created classmy_srvcwhich extends service.i have intialise object m_DBHandlerof class cl_DBHandlerin service but while initia

i have created class cl_DBHandlerwhich extends SQLiteOpenHelper. and i have created class my_srvcwhich extends service. i have intialise object m_DBHandlerof class cl_DBHandlerin service but while initialization object i have to pass parameters to cl_DBHandler(context, name, factory, version), i am not getting exactly what to pass in this. i have pass like this cl_DBHandler(getappcontext(),"databasename.sqlite",null,1)

2nd thing: i am calling one function from class with help of m_DBHandler object but i am getting value null of object m_DBHandler at every call though i have i开发者_Python百科ntialise that object in service.can anyone tell me or guide me to solve this problem.

Thanks in Advance--


Use the following constructor for your cl_DBHandler class

public static final String DATABASE_NAME = "MyDBName.db";
public static final int DATABASE_VERSION = 1;

public cl_DBHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

In your service or activity:

cl_DBHandler m_DBHandler = new cl_DBHandler(this);

Then open your database:

SQLiteDatabase db;
try {
        db = m_DBHandler.getWritableDatabase();

    } catch (SQLiteException ex) {
        db = m_DBHandler.getReadableDatabase();
    }
// do anything you like for example:
Cursor cursor = db.rawQuery(strQuery, null);
0

精彩评论

暂无评论...
验证码 换一张
取 消