wang_peng1 发表于 2013-1-26 15:58:36

sqllite帮助文件

<span class="Apple-style-span" style=""><span class="Apple-style-span" style="text-align: left; line-height: 18px; border-collapse: collapse; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px;">public class AnyDBAdapter {    private static final String TAG = "AnyDBAdapter";    private DatabaseHelper mDbHelper;    private static SQLiteDatabase mDb;    //make sure this matches the     //package com.MyPackage;    //at the top of this file    private static String DB_PATH = "/data/data/com.MyPackage/databases/";    //make sure this matches your database name in your assets folder    // my database file does not have an extension on it     // if yours does    // add the extention    private static final String DATABASE_NAME = "data";    //Im using an sqlite3 database, I have no clue if this makes a difference or not    private static final int DATABASE_VERSION = 3;    private final Context adapterContext;    public AnyDBAdapter(Context context) {        this.adapterContext = context;    }    public QuestDBAdapter open() throws SQLException {        mDbHelper = new DatabaseHelper(adapterContext);        try {            mDbHelper.createDataBase();        } catch (IOException ioe) {            throw new Error("Unable to create database");        }        try {            mDbHelper.openDataBase();        } catch (SQLException sqle) {            throw sqle;        }        return this;    }    //Usage from outside    // AnyDBAdapter dba = new AnyDBAdapter(contextObject); //in my case contextObject is a Map    // dba.open();    // Cursor c = dba.ExampleSelect("Rawr!");    // contextObject.startManagingCursor(c);    // String s1 = "", s2 = "";    // if(c.moveToFirst())    // do {    //  s1 = c.getString(0);    //  s2 = c.getString(1);    //  } while (c.moveToNext());    // dba.close();    public Cursor ExampleSelect(string myVariable)    {        String query = "SELECT locale, ? FROM android_metadata";        return mDb.rawQuery(query, new String[]{myVariable});    }    //Usage    // AnyDBAdatper dba = new AnyDBAdapter(contextObjecT);    // dba.open();    // dba.ExampleCommand("en-CA", "en-GB");    // dba.close();    public void ExampleCommand(String myVariable1, String myVariable2)    {        String command = "INSERT INTO android_metadata (locale) SELECT ? UNION ALL SELECT ?";        mDb.execSQL(command, new String[]{ myVariable1, myVariable2});    }    public void close() {        mDbHelper.close();    }    private static class DatabaseHelper extends SQLiteOpenHelper {        Context helperContext<span class="pun" style="">background-color: transparent; margin: 0px; color: #000000; font-size: 14px; vertical-align: baseline; border-
页: [1]
查看完整版本: sqllite帮助文件