Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>Damned! John J Smith has a more complete and faster answer!</em></p> <p>Android comes with SQLite, which is a very light on-board database engine.</p> <p>You can find lots of resources and tutorials on the Android Developer site or elsewhere on the internet, for example : </p> <ul> <li><a href="http://developer.android.com/guide/topics/data/data-storage.html#db" rel="nofollow">http://developer.android.com/guide/topics/data/data-storage.html#db</a></li> <li><a href="http://developer.android.com/resources/tutorials/notepad/index.html" rel="nofollow">http://developer.android.com/resources/tutorials/notepad/index.html</a></li> <li><a href="http://www.sqlite.org/" rel="nofollow">http://www.sqlite.org/</a></li> </ul> <p>Below is some code defining a class to cleanly manage a database (partially copied from the notepad tutorial referenced above).<br> To open the database, instantiate a MyDb object an call its open() method.</p> <pre><code>import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class MyDb { private class MyDbHelper extends SQLiteOpenHelper { MyDbHelper(Context context) { super(context, "myfirstdatabase", null, 1); } @Override public void onCreate(SQLiteDatabase db) { String createDbRequest = "CREATE TABLE .... "; // write the SQL query to create the first table db.execSQL(createDbRequest); // add other queries for more tables } } private MyDbHelper mDbHelper; private SQLiteDatabase mDb; private Context mContext; /** * Constructor - takes the context to allow the database to be * opened/created * * @param ctx the Context within which to work */ public MyDb(Context ctx) { mContext = ctx; } /** * Open the database. If it cannot be opened, try to create a new * instance of the database. If it cannot be created, throw an exception to * signal the failure * * @return this (self reference, allowing this to be chained in an * initialization call) * @throws SQLException if the database could be neither opened or created */ public MyDb open() throws SQLException { mDbHelper = new MyDbHelper(mContext); mDb = mDbHelper.getWritableDatabase(); return this; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload