{"id":15747,"date":"2014-10-24T15:00:12","date_gmt":"2014-10-24T12:00:12","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=15747"},"modified":"2019-04-24T15:59:22","modified_gmt":"2019-04-24T12:59:22","slug":"android-database-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/","title":{"rendered":"Android Database Example"},"content":{"rendered":"<p>In Android programming, storing data into a database is not a common practice, as we have other and most suitable methods to store our data, such as the <a href=\"http:\/\/developer.android.com\/reference\/android\/content\/SharedPreferences.html\">SharedPreferences<\/a> way.<\/p>\n<p>However, we do have a very strong tool, that can help our Android Application communicate with a database, and this is <a href=\"http:\/\/developer.android.com\/reference\/android\/database\/sqlite\/package-summary.html\">SQLite<\/a>. SQLite is an Open Source Database for structured data in relational databases. It is embedded in Android, to you don\u2019t have to do anything special to set up or administer an SQLite server.<\/p>\n<p>This example shows how to work with an SQLite database and how to make the basic actions. We will do this by following the DataModel and DataHandling structure. We will use a data access object (DAO) to manage the handling of the database connection and for accessing and modifying the data. By dealing with the database entries as Data Objects, it will be easier for us to present the sql queries results on our user interface.<\/p>\n<p>Let&#8217;s start! For our example will use the following tools in a Windows 64-bit or an  OS X platform:<\/p>\n<ul>\n<li>JDK 1.7<\/li>\n<li>Eclipse 4.2 Juno<\/li>\n<li>Android SDK 4.4.2<\/li>\n<\/ul>\n<p>Let\u2019s take a closer look:\n<\/p>\n<h2>1. Create a New Android Application Project<\/h2>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nYou may skip project creation and jump directly to the <a href=\"#code\"><strong>beginning of the example<\/strong><\/a> below.<\/div>\n<p>Open Eclipse IDE and go to File \u2192 New \u2192 Project \u2192 Android Application Project.<\/p>\n<p><figure id=\"attachment_13637\" aria-describedby=\"caption-attachment-13637\" style=\"width: 596px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample1.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample1.png\" alt=\"Figure 2. Create a new Android project\" width=\"596\" height=\"559\" class=\"size-full wp-image-13637\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample1.png 596w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample1-300x281.png 300w\" sizes=\"(max-width: 596px) 100vw, 596px\" \/><\/a><figcaption id=\"caption-attachment-13637\" class=\"wp-caption-text\">Figure 1. Create a new Android project<\/figcaption><\/figure><\/p>\n<p>Specify the name of the application, the project and the package and then click Next.<\/p>\n<p><figure id=\"attachment_13786\" aria-describedby=\"caption-attachment-13786\" style=\"width: 636px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-1.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-1.jpg\" alt=\"Figure 2. Create a new Android project name\" width=\"636\" height=\"543\" class=\"size-full wp-image-13786\"><\/a><figcaption id=\"caption-attachment-13786\" class=\"wp-caption-text\">Figure 2. Create a new Android project name<\/figcaption><\/figure><\/p>\n<p>In the next window, the \u201cCreate Activity\u201d option should be checked. The new created activity will be the main activity of your project. Then press Next button.<\/p>\n<p><figure id=\"attachment_11777\" aria-describedby=\"caption-attachment-11777\" style=\"width: 636px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-2.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-2.jpg\" alt=\"Create Activity\" width=\"636\" height=\"543\" class=\"alignnone size-full wp-image-13642\"><\/a><figcaption id=\"caption-attachment-11777\" class=\"wp-caption-text\">Figure 3. Configure the project<\/figcaption><\/figure><\/p>\n<p>In \u201cConfigure Launcher Icon\u201d window you should choose the icon you want to have in your app. We will use the default icon of android, so click Next.<\/p>\n<p><figure id=\"attachment_11778\" aria-describedby=\"caption-attachment-11778\" style=\"width: 660px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample4.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample4.png\" alt=\"Configure Launcher Icon\" width=\"660\" height=\"590\" class=\"alignnone size-full wp-image-13638\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample4.png 660w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample4-300x268.png 300w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/a><figcaption id=\"caption-attachment-11778\" class=\"wp-caption-text\">Figure 4. Configure the launcher icon<\/figcaption><\/figure><\/p>\n<p>Select the \u201cBlank Activity\u201d option and press Next.<\/p>\n<p><figure id=\"attachment_11779\" aria-describedby=\"caption-attachment-11779\" style=\"width: 660px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample5.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample5.png\" alt=\"Blank Activity\" width=\"660\" height=\"590\" class=\"alignnone size-full wp-image-13639\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample5.png 660w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/AndroidExample5-300x268.png 300w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/a><figcaption id=\"caption-attachment-11779\" class=\"wp-caption-text\">Figure 5. Create the activity and select its type<\/figcaption><\/figure><\/p>\n<p>You have to specify a name for the new Activity and a name for the layout description of your app. The .xml file for the layout will automatically be created in the res\/layout folder. It will also be created a fragment layout xml, that we are not going to use in this project and you can remove it if you want. Then press Finish.<\/p>\n<p><figure id=\"attachment_13788\" aria-describedby=\"caption-attachment-13788\" style=\"width: 720px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-3.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-3.jpg\" alt=\"Figure 6. Create a new blank activity\" width=\"720\" height=\"560\" class=\"size-full wp-image-13788\"><\/a><figcaption id=\"caption-attachment-13788\" class=\"wp-caption-text\">Figure 6. Create a new blank activity<\/figcaption><\/figure><\/p>\n<p>Here you can see, how will the structure of the project become when finished:<\/p>\n<p><figure id=\"attachment_13789\" aria-describedby=\"caption-attachment-13789\" style=\"width: 347px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-4.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-4.jpg\" alt=\"Figure 7. The tree of the project\" width=\"347\" height=\"487\" class=\"size-full wp-image-13789\"><\/a><figcaption id=\"caption-attachment-13789\" class=\"wp-caption-text\">Figure 7. The tree of the project<\/figcaption><\/figure><\/p>\n<p><span id=\"code\"> <\/span><\/p>\n<h2>2. Creating the layout of the main AndroidDatabaseExample<\/h2>\n<p>We are going to make a very simple layout xml for the <code>AndroidDatabaseExample.class<\/code>, that only consists of a <code>LinearLayout<\/code> that contains the one <code>ListView<\/code>.<\/p>\n<p>Open <code>res\/layout\/activity_main.xml<\/code>, go to the respective xml tab and paste the following:<\/p>\n<p><em><span style=\"text-decoration: underline\">activity_main.xml<\/span><\/em><\/p>\n<pre class=\"brush:xml; wrap-lines:false;\">&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:background=\"#ffffff\"\n    android:orientation=\"vertical\" &gt;\n\n    &lt;ListView\n        android:id=\"@android:id\/list\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\" &gt;\n    &lt;\/ListView&gt;\n\n&lt;\/LinearLayout&gt;\n<\/pre>\n<h2>3. Creating the Database and Data Model of the Activity AndroidDatabaseExample<\/h2>\n<p>Open <code>src\/com.javacodegeeks.androidcursorexample\/Book.java<\/code> file and paste the code below.<\/p>\n<p><em><span style=\"text-decoration: underline\">Book.java<\/span><\/em><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.androiddatabaseexample;\n\npublic class Book {\n\n\tprivate int id;\n\tprivate String title;\n\tprivate String author;\n\t\n\tpublic Book(){}\n\t\n\tpublic Book(String title, String author) {\n\t\tsuper();\n\t\tthis.title = title;\n\t\tthis.author = author;\n\t}\n\t\n\tpublic int getId() {\n\t\treturn id;\n\t}\n\tpublic void setId(int id) {\n\t\tthis.id = id;\n\t}\n\tpublic String getTitle() {\n\t\treturn title;\n\t}\n\tpublic void setTitle(String title) {\n\t\tthis.title = title;\n\t}\n\tpublic String getAuthor() {\n\t\treturn author;\n\t}\n\tpublic void setAuthor(String author) {\n\t\tthis.author = author;\n\t}\n\t\n\t@Override\n\tpublic String toString() {\n\t\treturn \"Book [id=\" + id + \", title=\" + title + \", author=\" + author\n\t\t\t\t+ \"]\";\n\t}\n}\n<\/pre>\n<p>The Book class is our model and contains the data we will save in the database and show in the user interface.<\/p>\n<p>Now, open <code>src\/com.javacodegeeks.androidcursorexample\/JCGSQLiteHelper.java<\/code> file and paste the code below.<\/p>\n<p><em><span style=\"text-decoration: underline\">JCGSQLiteHelper.java<\/span><\/em><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.androiddatabaseexample;\n\nimport java.util.LinkedList;\nimport java.util.List;\n\nimport android.content.ContentValues;\nimport android.content.Context;\nimport android.database.Cursor;\nimport android.database.sqlite.SQLiteDatabase;\nimport android.database.sqlite.SQLiteOpenHelper;\n\npublic class JCGSQLiteHelper extends SQLiteOpenHelper {\n\n\t\/\/ database version\n\tprivate static final int database_VERSION = 1;\n\t\/\/ database name\n\tprivate static final String database_NAME = \"BookDB\";\n\tprivate static final String table_BOOKS = \"books\";\n\tprivate static final String book_ID = \"id\";\n\tprivate static final String book_TITLE = \"title\";\n\tprivate static final String book_AUTHOR = \"author\";\n\n\tprivate static final String[] COLUMNS = { book_ID, book_TITLE, book_AUTHOR };\n\n\tpublic JCGSQLiteHelper(Context context) {\n\t\tsuper(context, database_NAME, null, database_VERSION);\n\t}\n\n\t@Override\n\tpublic void onCreate(SQLiteDatabase db) {\n\t\t\/\/ SQL statement to create book table\n\t\tString CREATE_BOOK_TABLE = \"CREATE TABLE books ( \" + \"id INTEGER PRIMARY KEY AUTOINCREMENT, \" + \"title TEXT, \" + \"author TEXT )\";\n\t\tdb.execSQL(CREATE_BOOK_TABLE);\n\t}\n\n\t@Override\n\tpublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {\n\t\t\/\/ drop books table if already exists\n\t\tdb.execSQL(\"DROP TABLE IF EXISTS books\");\n\t\tthis.onCreate(db);\n\t}\n\n\tpublic void createBook(Book book) {\n\t\t\/\/ get reference of the BookDB database\n\t\tSQLiteDatabase db = this.getWritableDatabase();\n\n\t\t\/\/ make values to be inserted\n\t\tContentValues values = new ContentValues();\n\t\tvalues.put(book_TITLE, book.getTitle());\n\t\tvalues.put(book_AUTHOR, book.getAuthor());\n\n\t\t\/\/ insert book\n\t\tdb.insert(table_BOOKS, null, values);\n\n\t\t\/\/ close database transaction\n\t\tdb.close();\n\t}\n\n\tpublic Book readBook(int id) {\n\t\t\/\/ get reference of the BookDB database\n\t\tSQLiteDatabase db = this.getReadableDatabase();\n\n\t\t\/\/ get book query\n\t\tCursor cursor = db.query(table_BOOKS, \/\/ a. table\n\t\t\t\tCOLUMNS, \" id = ?\", new String[] { String.valueOf(id) }, null, null, null, null);\n\n\t\t\/\/ if results !=null, parse the first one\n\t\tif (cursor != null)\n\t\t\tcursor.moveToFirst();\n\n\t\tBook book = new Book();\n\t\tbook.setId(Integer.parseInt(cursor.getString(0)));\n\t\tbook.setTitle(cursor.getString(1));\n\t\tbook.setAuthor(cursor.getString(2));\n\n\t\treturn book;\n\t}\n\n\tpublic List getAllBooks() {\n\t\tList books = new LinkedList();\n\n\t\t\/\/ select book query\n\t\tString query = \"SELECT  * FROM \" + table_BOOKS;\n\n\t\t\/\/ get reference of the BookDB database\n\t\tSQLiteDatabase db = this.getWritableDatabase();\n\t\tCursor cursor = db.rawQuery(query, null);\n\n\t\t\/\/ parse all results\n\t\tBook book = null;\n\t\tif (cursor.moveToFirst()) {\n\t\t\tdo {\n\t\t\t\tbook = new Book();\n\t\t\t\tbook.setId(Integer.parseInt(cursor.getString(0)));\n\t\t\t\tbook.setTitle(cursor.getString(1));\n\t\t\t\tbook.setAuthor(cursor.getString(2));\n\n\t\t\t\t\/\/ Add book to books\n\t\t\t\tbooks.add(book);\n\t\t\t} while (cursor.moveToNext());\n\t\t}\n\t\treturn books;\n\t}\n\n\tpublic int updateBook(Book book) {\n\n\t\t\/\/ get reference of the BookDB database\n\t\tSQLiteDatabase db = this.getWritableDatabase();\n\n\t\t\/\/ make values to be inserted\n\t\tContentValues values = new ContentValues();\n\t\tvalues.put(\"title\", book.getTitle()); \/\/ get title\n\t\tvalues.put(\"author\", book.getAuthor()); \/\/ get author\n\n\t\t\/\/ update\n\t\tint i = db.update(table_BOOKS, values, book_ID + \" = ?\", new String[] { String.valueOf(book.getId()) });\n\n\t\tdb.close();\n\t\treturn i;\n\t}\n\n\t\/\/ Deleting single book\n\tpublic void deleteBook(Book book) {\n\n\t\t\/\/ get reference of the BookDB database\n\t\tSQLiteDatabase db = this.getWritableDatabase();\n\n\t\t\/\/ delete book\n\t\tdb.delete(table_BOOKS, book_ID + \" = ?\", new String[] { String.valueOf(book.getId()) });\n\t\tdb.close();\n\t}\n}\n<\/pre>\n<p>This class is responsible for all the actions that will take place on the database. Let&#8217;s see in detail the code above.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>The <code>JCGSQLiteHelper.class<\/code> contains the basic methods:<br \/>\n<code>onCreate(SQLiteDatabase db)<\/code>, called when the database is created for the first time.<br \/>\n<code>onUpgrade(SQLiteDatabase db<\/code>, int oldVersion, int newVersion), called when the database needs to be upgraded.<\/p>\n<p>For our example, we have extended our data management class, in order to include the methods for inserting, deleting, and updating a book in our database.<\/p>\n<pre class=\"brush:java; wrap-lines:false\">\tpublic void createBook(Book book) {\t\n\t\tSQLiteDatabase db = this.getWritableDatabase();\n\t\tContentValues values = new ContentValues();\n\t\tvalues.put(book_TITLE, book.getTitle());\n\t\tvalues.put(book_AUTHOR, book.getAuthor());\n\t\t\n\t\tdb.insert(table_BOOKS, null, values);\n\t\tdb.close();\n\t}\n<\/pre>\n<p>In the code snipped above, we get reference of the BookDB database and create an insert query in order to insert the values of the <b>book_TITLE<\/b> and <b>book_AUTHOR<\/b> rows. We execute the insert and then close the transaction.<\/p>\n<pre class=\"brush:java; wrap-lines:false\">\tpublic Book readBook(int id) {\n\t\tSQLiteDatabase db = this.getReadableDatabase();\n\t\tCursor cursor = db.query(table_BOOKS, \/\/ a. table\n\t\t\t\tCOLUMNS, \" id = ?\", new String[] { String.valueOf(id) }, null, null, null, null);\n\t\tif (cursor != null)\n\t\t\tcursor.moveToFirst();\n\n\t\tBook book = new Book();\n\t\tbook.setId(Integer.parseInt(cursor.getString(0)));\n\t\tbook.setTitle(cursor.getString(1));\n\t\tbook.setAuthor(cursor.getString(2));\n\n\t\treturn book;\n\t}\n<\/pre>\n<p>With the code above, we get reference of the BookDB database and create an search query in order to find a specific book entry. We execute the search and then we return the first of the results as a book Object.<\/p>\n<p>In the same way we get all the books of the database:<\/p>\n<pre class=\"brush:java; wrap-lines:false\">\tpublic List getAllBooks() {\n\t\tList books = new LinkedList();\n\n\t\t\/\/ select book query\n\t\tString query = \"SELECT  * FROM \" + table_BOOKS;\n\n\t\t\/\/ get reference of the BookDB database\n\t\tSQLiteDatabase db = this.getWritableDatabase();\n\t\tCursor cursor = db.rawQuery(query, null);\n\n\t\t\/\/ parse all results\n\t\tBook book = null;\n\t\tif (cursor.moveToFirst()) {\n\t\t\tdo {\n\t\t\t\tbook = new Book();\n\t\t\t\tbook.setId(Integer.parseInt(cursor.getString(0)));\n\t\t\t\tbook.setTitle(cursor.getString(1));\n\t\t\t\tbook.setAuthor(cursor.getString(2));\n\n\t\t\t\t\/\/ Add book to books\n\t\t\t\tbooks.add(book);\n\t\t\t} while (cursor.moveToNext());\n\t\t}\n\t\treturn books;\n\t}\n\n<\/pre>\n<p>We have also implemented an update book method:<\/p>\n<pre class=\"brush:java; wrap-lines:false\">\tpublic int updateBook(Book book) {\n\t\tSQLiteDatabase db = this.getWritableDatabase();\n\t\tContentValues values = new ContentValues();\n\t\tvalues.put(\"title\", book.getTitle());\n\t\tvalues.put(\"author\", book.getAuthor());r\n\t\tint i = db.update(table_BOOKS, values, book_ID + \" = ?\", new String[] { String.valueOf(book.getId()) });\n\n\t\tdb.close();\n\t\treturn i;\n\t}\n<\/pre>\n<p>In the code snipped above, we get reference of the BookDB database and create an update query in order to change the values of an already added book in the database. We execute the update and then close the transaction.<\/p>\n<pre class=\"brush:java; wrap-lines:false\">\tpublic void deleteBook(Book book) {\n\t\tSQLiteDatabase db = this.getWritableDatabase();\n\t\tdb.delete(table_BOOKS, book_ID + \" = ?\", new String[] { String.valueOf(book.getId()) });\n\t\tdb.close();\n\t}\n<\/pre>\n<p>With the above code we delete a book entry from our database, after of course, we take the reference of the BookDB database and create an delete query.<\/p>\n<h2>4. Creating the source code of the main AndroidDatabaseExampleActivity<\/h2>\n<p>Open <code>src\/com.javacodegeeks.androidcursorexample\/AndroidDatabaseExample.java<\/code> file and paste the code below.<\/p>\n<p><em><span style=\"text-decoration: underline\">AndroidDatabaseExample.java<\/span><\/em><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.androiddatabaseexample;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport android.app.ListActivity;\nimport android.content.Intent;\nimport android.os.Bundle;\nimport android.view.View;\nimport android.widget.AdapterView;\nimport android.widget.AdapterView.OnItemClickListener;\nimport android.widget.ArrayAdapter;\n\npublic class AndroidDatabaseExample extends ListActivity implements OnItemClickListener {\n\tJCGSQLiteHelper db = new JCGSQLiteHelper(this);\n\tList list;\n\tArrayAdapter myAdapter;\n\n\t@Override\n\tpublic void onCreate(Bundle savedInstanceState) {\n\t\tsuper.onCreate(savedInstanceState);\n\n\t\tsetContentView(R.layout.activity_main);\n\n\t\t\/\/ drop this database if already exists\n\t\tdb.onUpgrade(db.getWritableDatabase(), 1, 2);\n\n\t\tdb.createBook(new Book(\"The Great Gatsby\", \"F. Scott Fitzgerald\"));\n\t\tdb.createBook(new Book(\"Anna Karenina\", \"Leo Tolstoy\"));\n\t\tdb.createBook(new Book(\"The Grapes of Wrath\", \"John Steinbeck\"));\n\t\tdb.createBook(new Book(\"Invisible Man\", \"Ralph Ellison\"));\n\t\tdb.createBook(new Book(\"Gone with the Wind\", \"Margaret Mitchell\"));\n\t\tdb.createBook(new Book(\"Pride and Prejudice\", \"Jane Austen\"));\n\t\tdb.createBook(new Book(\"Sense and Sensibility\", \"Jane Austen\"));\n\t\tdb.createBook(new Book(\"Mansfield Park\", \"Jane Austen\"));\n\t\tdb.createBook(new Book(\"The Color Purple\", \"Alice Walker\"));\n\t\tdb.createBook(new Book(\"The Temple of My Familiar\", \"Alice Walker\"));\n\t\tdb.createBook(new Book(\"The waves\", \"Virginia Woolf\"));\n\t\tdb.createBook(new Book(\"Mrs Dalloway\", \"Virginia Woolf\"));\n\t\tdb.createBook(new Book(\"War and Peace\", \"Leo Tolstoy\"));\n\n\t\t\/\/ get all books\n\t\tlist = db.getAllBooks();\n\t\tList listTitle = new ArrayList();\n\n\t\tfor (int i = 0; i &lt; list.size(); i++) {\n\t\t\tlistTitle.add(i, list.get(i).getTitle());\n\t\t}\n\n\t\tmyAdapter = new ArrayAdapter(this, R.layout.row_layout, R.id.listText, listTitle);\n\t\tgetListView().setOnItemClickListener(this);\n\t\tsetListAdapter(myAdapter);\n\t}\n\n\t@Override\n\tpublic void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {\n\t\t\/\/ start BookActivity with extras the book id\n\t\tIntent intent = new Intent(this, BookActivity.class);\n\t\tintent.putExtra(\"book\", list.get(arg2).getId());\n\t\tstartActivityForResult(intent, 1);\n\t}\n\n\t@Override\n\tprotected void onActivityResult(int requestCode, int resultCode, Intent data) {\n\t\tsuper.onActivityResult(requestCode, resultCode, data);\n\n\t\t\/\/ get all books again, because something changed\n\t\tlist = db.getAllBooks();\n\n\t\tList listTitle = new ArrayList();\n\n\t\tfor (int i = 0; i &lt; list.size(); i++) {\n\t\t\tlistTitle.add(i, list.get(i).getTitle());\n\t\t}\n\n\t\tmyAdapter = new ArrayAdapter(this, R.layout.row_layout, R.id.listText, listTitle);\n\t\tgetListView().setOnItemClickListener(this);\n\t\tsetListAdapter(myAdapter);\n\t}\n}\n<\/pre>\n<p>Open <code>src\/com.javacodegeeks.androidcursorexample\/BookActivity.java<\/code> file and paste the code below.[ulp id=&#8217;Ja8Orb5oPKdShcXt&#8217;]<\/p>\n<p><em><span style=\"text-decoration: underline\">BookActivity.java<\/span><\/em><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.androiddatabaseexample;\n\nimport android.app.Activity;\nimport android.content.Intent;\nimport android.os.Bundle;\nimport android.view.View;\nimport android.widget.EditText;\nimport android.widget.TextView;\nimport android.widget.Toast;\n\npublic class BookActivity extends Activity {\n\tTextView bookTitle;\n\tTextView authorName;\n\tBook selectedBook;\n\tJCGSQLiteHelper db;\n\n\t@Override\n\tpublic void onCreate(Bundle savedInstanceState) {\n\n\t\tsuper.onCreate(savedInstanceState);\n\n\t\tsetContentView(R.layout.activity_book);\n\n\t\tbookTitle = (TextView) findViewById(R.id.title);\n\t\tauthorName = (TextView) findViewById(R.id.author);\n\n\t\t\/\/ get the intent that we have passed from AndroidDatabaseExample\n\t\tIntent intent = getIntent();\n\t\tint id = intent.getIntExtra(\"book\", -1);\n\n\t\t\/\/ open the database of the application context\n\t\tdb = new JCGSQLiteHelper(getApplicationContext());\n\n\t\t\/\/ read the book with \"id\" from the database\n\t\tselectedBook = db.readBook(id);\n\n\t\tinitializeViews();\n\t}\n\n\tpublic void initializeViews() {\n\t\tbookTitle.setText(selectedBook.getTitle());\n\t\tauthorName.setText(selectedBook.getAuthor());\n\t}\n\n\tpublic void update(View v) {\n\t\tToast.makeText(getApplicationContext(), \"This book is updated.\", Toast.LENGTH_SHORT).show();\n\t\tselectedBook.setTitle(((EditText) findViewById(R.id.titleEdit)).getText().toString());\n\t\tselectedBook.setAuthor(((EditText) findViewById(R.id.authorEdit)).getText().toString());\n\n\t\t\/\/ update book with changes\n\t\tdb.updateBook(selectedBook);\n\t\tfinish();\n\t}\n\n\tpublic void delete(View v) {\n\t\tToast.makeText(getApplicationContext(), \"This book is deleted.\", Toast.LENGTH_SHORT).show();\n\n\t\t\/\/ delete selected book\n\t\tdb.deleteBook(selectedBook);\n\t\tfinish();\n\t}\n}\n<\/pre>\n<h2>5. Creating the layout of the BookActivity<\/h2>\n<p>We are going to make a simple layout xml for the <code>BookActivity.class<\/code>, the Activity that can delete and update the book entries in the database.<\/p>\n<p>Open <code>res\/layout\/activity_book.xml<\/code>, go to the respective xml tab and paste the following:<\/p>\n<p><em><span style=\"text-decoration: underline\">activity_book.xml<\/span><\/em><\/p>\n<pre class=\"brush:xml; wrap-lines:false;\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:orientation=\"vertical\"\n    android:padding=\"25dp\" &gt;\n\n    &lt;LinearLayout\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:layout_marginBottom=\"10dp\"\n        android:layout_marginLeft=\"5dp\" &gt;\n\n        &lt;TextView\n            android:id=\"@+id\/titleLabel\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:text=\"Title: \"\n            android:textAppearance=\"?android:attr\/textAppearanceLarge\" \/&gt;\n\n        &lt;TextView\n            android:id=\"@+id\/title\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:text=\"Book Title\"\n            android:textAppearance=\"?android:attr\/textAppearanceLarge\" \/&gt;\n    &lt;\/LinearLayout&gt;\n\n    &lt;LinearLayout\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:layout_marginBottom=\"10dp\"\n        android:layout_marginLeft=\"5dp\" &gt;\n\n        &lt;TextView\n            android:id=\"@+id\/authorLabel\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:text=\"Author: \"\n            android:textAppearance=\"?android:attr\/textAppearanceLarge\" \/&gt;\n\n        &lt;TextView\n            android:id=\"@+id\/author\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:text=\"Book Title\"\n            android:textAppearance=\"?android:attr\/textAppearanceLarge\" \/&gt;\n    &lt;\/LinearLayout&gt;\n\n    &lt;Button\n        android:id=\"@+id\/delete\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:layout_marginBottom=\"30dp\"\n        android:onClick=\"delete\"\n        android:text=\"Delete Book\" \/&gt;\n\n    &lt;LinearLayout\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:layout_marginBottom=\"10dp\"\n        android:layout_marginLeft=\"5dp\" &gt;\n\n        &lt;TextView\n            android:id=\"@+id\/titleEditLabel\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:text=\"Title: \"\n            android:textAppearance=\"?android:attr\/textAppearanceLarge\" \/&gt;\n\n        &lt;EditText\n            android:id=\"@+id\/titleEdit\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:layout_marginLeft=\"5dp\"\n            android:layout_weight=\"1\"\n            android:ems=\"10\" &gt;\n\n            &lt;requestFocus \/&gt;\n        &lt;\/EditText&gt;\n    &lt;\/LinearLayout&gt;\n\n    &lt;LinearLayout\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:layout_marginBottom=\"10dp\"\n        android:layout_marginLeft=\"5dp\" &gt;\n\n        &lt;TextView\n            android:id=\"@+id\/authorEditLabel\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:text=\"Author: \"\n            android:textAppearance=\"?android:attr\/textAppearanceLarge\" \/&gt;\n\n        &lt;EditText\n            android:id=\"@+id\/authorEdit\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:layout_marginLeft=\"5dp\"\n            android:layout_weight=\"1\"\n            android:ems=\"10\" &gt;\n        &lt;\/EditText&gt;\n    &lt;\/LinearLayout&gt;\n\n    &lt;Button\n        android:id=\"@+id\/update\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:onClick=\"update\"\n        android:text=\"Update Book\" \/&gt;\n\n&lt;\/LinearLayout&gt;\n<\/pre>\n<h2>6. Build, compile and run<\/h2>\n<p>When we build, compile and run our project, the main AndroidDatabaseExample should look like this:<\/p>\n<p><figure id=\"attachment_14193\" aria-describedby=\"caption-attachment-14193\" style=\"width: 400px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-5.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-5.jpg\" alt=\"Figure 8. Figure This is how the main Activity looks like\" width=\"400\" height=\"711\" class=\"size-full wp-image-14193\"><\/a><figcaption id=\"caption-attachment-14193\" class=\"wp-caption-text\">Figure 8. Figure This is how the main Activity looks like.<\/figcaption><\/figure><br \/>\n<figure id=\"attachment_14193\" aria-describedby=\"caption-attachment-14193\" style=\"width: 400px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-6.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-6.jpg\" alt=\"Figure 9. This is how the BookActivity looks like\" width=\"400\" height=\"711\" class=\"size-full wp-image-14193\"><\/a><figcaption id=\"caption-attachment-14193\" class=\"wp-caption-text\">Figure 9. This is how the BookActivity looks like.<\/figcaption><\/figure><br \/>\n<figure id=\"attachment_14193\" aria-describedby=\"caption-attachment-14193\" style=\"width: 400px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-7.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-7.jpg\" alt=\"Figure 10. This is our book list, after we have deleted the book in the BookActivity.\" width=\"400\" height=\"711\" class=\"size-full wp-image-14193\"><\/a><figcaption id=\"caption-attachment-14193\" class=\"wp-caption-text\">Figure 10. This is our book list, after we have deleted the book in the BookActivity.<\/figcaption><\/figure><br \/>\n<figure id=\"attachment_14193\" aria-describedby=\"caption-attachment-14193\" style=\"width: 400px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-8.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample-8.jpg\" alt=\"Figure 11. In this figure we see how we can update a book in our database.\" width=\"400\" height=\"711\" class=\"size-full wp-image-14193\"><\/a><figcaption id=\"caption-attachment-14193\" class=\"wp-caption-text\">Figure 11. In this figure we see how we can update a book in our database.<\/figcaption><\/figure><\/p>\n<h2>Download the Eclipse Project<\/h2>\n<p>This was an example of Android AndroidDatabaseExample.<\/p>\n<div class=\"download\"><strong>Download<br \/>\n<\/strong>You can download the full source code of this example here:  <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/10\/AndroidDatabaseExample.zip\"><strong>AndroidDatabaseExample<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In Android programming, storing data into a database is not a common practice, as we have other and most suitable methods to store our data, such as the SharedPreferences way. However, we do have a very strong tool, that can help our Android Application communicate with a database, and this is SQLite. SQLite is an &hellip;<\/p>\n","protected":false},"author":14,"featured_media":1202,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[446],"tags":[],"class_list":["post-15747","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android Database Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In Android programming, storing data into a database is not a common practice, as we have other and most suitable methods to store our data, such as the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android Database Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In Android programming, storing data into a database is not a common practice, as we have other and most suitable methods to store our data, such as the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-10-24T12:00:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-24T12:59:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Chryssa Aliferi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Chryssa Aliferi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/\"},\"author\":{\"name\":\"Chryssa Aliferi\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/863144453b9fc15d4184d71833dcf332\"},\"headline\":\"Android Database Example\",\"datePublished\":\"2014-10-24T12:00:12+00:00\",\"dateModified\":\"2019-04-24T12:59:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/\"},\"wordCount\":1010,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"articleSection\":[\"database\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/\",\"name\":\"Android Database Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"datePublished\":\"2014-10-24T12:00:12+00:00\",\"dateModified\":\"2019-04-24T12:59:22+00:00\",\"description\":\"In Android programming, storing data into a database is not a common practice, as we have other and most suitable methods to store our data, such as the\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"core\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"database\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/database\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Android Database Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/863144453b9fc15d4184d71833dcf332\",\"name\":\"Chryssa Aliferi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/Chryssa-Aliferi-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/Chryssa-Aliferi-96x96.jpg\",\"caption\":\"Chryssa Aliferi\"},\"description\":\"Chryssa is a Computer Science graduate from Athens University of Economic and Business. During her studies, Chryssa carried out a great variety of projects ranging from networking to software engineering. She is very keen on front end development especially on mobile technologies and web applications. She has worked as a junior Software Engineer in the telecommunications area and currently works as an Android Developer.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/chryssa-aliferi\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android Database Example - Java Code Geeks","description":"In Android programming, storing data into a database is not a common practice, as we have other and most suitable methods to store our data, such as the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/","og_locale":"en_US","og_type":"article","og_title":"Android Database Example - Java Code Geeks","og_description":"In Android programming, storing data into a database is not a common practice, as we have other and most suitable methods to store our data, such as the","og_url":"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-10-24T12:00:12+00:00","article_modified_time":"2019-04-24T12:59:22+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","type":"image\/jpeg"}],"author":"Chryssa Aliferi","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Chryssa Aliferi","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/"},"author":{"name":"Chryssa Aliferi","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/863144453b9fc15d4184d71833dcf332"},"headline":"Android Database Example","datePublished":"2014-10-24T12:00:12+00:00","dateModified":"2019-04-24T12:59:22+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/"},"wordCount":1010,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","articleSection":["database"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/","url":"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/","name":"Android Database Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","datePublished":"2014-10-24T12:00:12+00:00","dateModified":"2019-04-24T12:59:22+00:00","description":"In Android programming, storing data into a database is not a common practice, as we have other and most suitable methods to store our data, such as the","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/database\/android-database-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Android","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/"},{"@type":"ListItem","position":3,"name":"core","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/"},{"@type":"ListItem","position":4,"name":"database","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/database\/"},{"@type":"ListItem","position":5,"name":"Android Database Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/863144453b9fc15d4184d71833dcf332","name":"Chryssa Aliferi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/Chryssa-Aliferi-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/Chryssa-Aliferi-96x96.jpg","caption":"Chryssa Aliferi"},"description":"Chryssa is a Computer Science graduate from Athens University of Economic and Business. During her studies, Chryssa carried out a great variety of projects ranging from networking to software engineering. She is very keen on front end development especially on mobile technologies and web applications. She has worked as a junior Software Engineer in the telecommunications area and currently works as an Android Developer.","sameAs":["http:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/examples.javacodegeeks.com\/author\/chryssa-aliferi\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/15747","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=15747"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/15747\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1202"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=15747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=15747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=15747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}