Маленький шаблон, для работы с SQLite:
public class DBAdapter
{
private static final String DATABASE_NAME = "test";
private static final int DATABASE_VERSION = 1;
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DBAdapter(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) {
// TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}
public SQLiteDatabase GetDataBaseOpen() throws SQLException
{
return this.db;
}
public DBAdapter Open() throws SQLiteException
{
db = DBHelper.getWritableDatabase();
return this;
}
public DBAdapter OpenForRead() throws SQLiteException
{
db = DBHelper.getReadableDatabase();
return this;
}
public void Close()
{
DBHelper.close();
}
}