[Java for Android App Development] zalez:
Here is my DB class that I use. I stripped alot of my functions out but left some to show how I access the DB.

To Call from any activity:

DBAdapter db = new DBAdapter(this);

db.open();
db.AnyFunctionYouCreate();
db.close();

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBAdapter
{
public static final String KEY_ROWID = "_id";

private static final String TAG = "DBAdapter";

private static final String DATABASE_NAME = "YourAppName";
private static final int DATABASE_VERSION = 4; //(increased 6/13)increase this when changing db layout

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);
}

[MENTION=439709]override[/MENTION]
public void onCreate(SQLiteDatabase db)
{
db.execSQL("SQL_TO_CREATE_TABLES_HERE");

}

[MENTION=439709]override[/MENTION]
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 your_table");

onCreate(db);
}
}
public Cursor lastId() {
Cursor yCursor = db.rawQuery("SELECT last_insert_rowid();", null);
if (yCursor != null){
yCursor.moveToFirst();
}
return yCursor;
}

//---opens the database---
public DBAdapter open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}

//---closes the database---
public void close()
{
DBHelper.close();
}

//---retrieves all responses---
public Cursor getCustomResponse(String number)
{
Cursor cur = db.rawQuery("SELECT " + REP_RESPONSE +
" from " + MY_REPLIES + " where " + REP_AUDIENCE + " = " + number ,new String [] {});

return cur;
/*return db.query(MY_REPLIES, new String[] {
KEY_ROWID,
REP_RESPONSE,
REP_AUDIENCE},
null,
null,
null,
null,
null);*/
}
public Cursor getSetting(String what_table, String what_item)
{
Cursor cur = db.rawQuery("SELECT " + what_item +
" from " + what_table ,new String [] {});

return cur;

}

/**
* Updates Settings Table
*
* [MENTION=955119]param[/MENTION] long RowId
* [MENTION=955119]param[/MENTION] String Response
* [MENTION=955119]param[/MENTION] String LocationStatus
* [MENTION=955119]param[/MENTION] String LocationPassword
* [MENTION=955119]param[/MENTION] String TTSStatus
* [MENTION=955119]param[/MENTION] String VoiceReply
* [MENTION=955119]param[/MENTION] String AppendMsg
* [MENTION=955119]param[/MENTION] String NoReplyTimer
* [MENTION=2056652]return[/MENTION] boolean
*/
public boolean updateSetting(long rowId, String settingResponse,
String locatorStatus, String locatorPass, String tts, String reply, String msgAppend, String timeDelay,
String auto, String silent, String shake)
{
ContentValues initialValues = new ContentValues();

initialValues.put(BUT_RESPONSE, settingResponse);
initialValues.put(BUT_LOCATOR, locatorStatus);
initialValues.put(BUT_LOC_PASS, locatorPass);
initialValues.put(BUT_TTS, tts);
initialValues.put(BUT_VOICE, reply);
initialValues.put(BUT_APPEND, msgAppend);
initialValues.put(BUT_TIME, timeDelay);
initialValues.put(BUT_AUTO_OFF, auto);
initialValues.put(BUT_SILENT, silent);
initialValues.put(BUT_SHAKE, shake);
return db.update(BUTLER_SETTINGS, initialValues,
KEY_ROWID + "=" + rowId, null) > 0;
}

public void emptySmsLog(){
db.execSQL("DELETE FROM sms_log;");
}
}