

{"id":78255,"date":"2020-05-28T11:58:41","date_gmt":"2020-05-28T06:28:41","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=78255"},"modified":"2024-08-22T22:03:32","modified_gmt":"2024-08-22T16:33:32","slug":"android-sqlite","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/android-sqlite\/","title":{"rendered":"Android SQLite Database for Android Developers"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:1091,&quot;href&quot;:&quot;https:\\\/\\\/docs.microsoft.com\\\/en-us\\\/dotnet\\\/api\\\/android.database.sqlite.sqliteopenhelper?view=xamarin-android-sdk-9&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;https:\\\/\\\/learn.microsoft.com\\\/en-us\\\/dotnet\\\/api\\\/android.database.sqlite.sqliteopenhelper?view=xamarin-android-sdk-9&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>In this tutorial, we\u2019ll learn about <strong>Android SQLite Database<\/strong>. Till now, we\u2019ve already read the different <a href=\"https:\/\/data-flair.training\/blogs\/storage-in-android\/\">ways to store the data in Android<\/a> like internal storage, external storage, and preferences. This technique is a useful option for the storage of small quantities of data. Thus, to store, maintain, and retrieve large amounts of data, we\u2019ll prefer the SQLite database in Android. So, before we start with SQLite in Android, we\u2019ll understand what SQLite is.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/05\/Android-SQLite-Database.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78268\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/05\/Android-SQLite-Database.jpg\" alt=\"Android SQLite Database\" width=\"802\" height=\"420\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/05\/Android-SQLite-Database.jpg 802w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/05\/Android-SQLite-Database-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/05\/Android-SQLite-Database-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/05\/Android-SQLite-Database-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/05\/Android-SQLite-Database-520x272.jpg 520w\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" \/><\/a><\/p>\n<h2>What is SQLite?<\/h2>\n<p>SQLite is basically a Relational Database Management System (RDBMS), same as SQL. It is an open-source in-process library that is self-contained, serverless, has zero-configuration, and a transactional SQL database engine. Here, zero-configuration means unlike other database management systems, it doesn\u2019t need to be configured on the devices. The Lite here in SQLite is in terms of its setup, the database administration, and all the required resources.<\/p>\n<p>RDBMS has: tables, indices, procedures, etc\u2026. The different operations such as creating a table, manipulation of entries and different operations can be directly done.<\/p>\n<h2>Features of Android SQLite<\/h2>\n<p>SQLite has many features which it supports as follows:<\/p>\n<ul>\n<li>Full-featured SQL implementation along with various advanced capabilities such as partial indexing, JSON, and some other.<\/li>\n<li>Very simple with easy to use API.<\/li>\n<li>Has a really fast execution at times, and it is even faster than the direct file system Input-Output.<\/li>\n<li>Self-dependent as it has no external dependencies.<\/li>\n<li>Transactions in SQlite also have the ACID property that is &#8211; Atomicity, Consistency, Isolation, and Durability.<\/li>\n<li>Cross-platform as it supports Android, iOS, Linux, Mac, Windows, VxWorks, Solaris. It is easy to port it to other systems.<\/li>\n<li>Comes along with a standalone command-line interface client.<\/li>\n<li>Completely stored in a single cross-platform.<\/li>\n<li>Written completely in ANSI-C.<\/li>\n<li>Highly lightweight and small, as it is possible to configure it in less than 400Kbs. If configured by omitting the optional features, it uses less than 250Kbs.<\/li>\n<li>Custom functions are possible to implement.<\/li>\n<li>Allows the use of virtual tables<\/li>\n<li>Allows the use of procedures and triggers in SQL<\/li>\n<li>Free to use without any payment and subscription.<\/li>\n<\/ul>\n<h2>SQLite in Android<\/h2>\n<p>So, we know that SQLite is an open-source RDBMS used to perform operations on the databases stored in the form of rows and columns.<\/p>\n<p>SQLite is highly supported by Android; in fact, Android comes with the built-in database implementation of SQLite. It is available on each and every Android database and emphasizes scalability, centralization, concurrency, and control. This strives to provide storage at the local level for applications and devices. It is highly economical, efficient, reliable, and independent. It is very simple and doesn\u2019t need to be compared with client\/server databases.<\/p>\n<p>1. SQLite supports the following three types of data:<\/p>\n<ul>\n<li><strong>Text Type<\/strong> &#8211; to store strings or character type data.<\/li>\n<li><strong>Integer<\/strong> Type &#8211; to store the integer data type.<\/li>\n<li><strong>Real Type<\/strong> &#8211; to store long values.<\/li>\n<\/ul>\n<p>In SQLite, the data types that are used are termed as valid; it is not validated by SQLite.<\/p>\n<p>2. To use SQLite in Android applications, we use the package <strong>android.database.sqlite<\/strong>. This package contains all the APIs to use SQLite.<\/p>\n<p>3. <strong>SQLiteOpenHelper<\/strong> is a class that is useful to create the database and manage it. The two constructors of <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/android.database.sqlite.sqliteopenhelper?view=xamarin-android-sdk-9\">SQLiteOpenHelper class<\/a> are:<\/p>\n<ul>\n<li><strong>SQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version_no)<\/strong> &#8211; It creates objects for creating, opening, and managing the database.<\/li>\n<li><strong>SQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version_no, DatabaseErrorHandler errorHandler<\/strong>) &#8211; Its object specifies the error handler along with creating, opening, and managing the database.<\/li>\n<\/ul>\n<p>4. <strong>SQLiteDatabase<\/strong> is a class that has methods to perform operations such as create, update, delete, etc.<br \/>\nThere are many methods that it includes, and a few of them are as follows :<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Methods<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Void execSQL(String sql_query)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will execute SQLquery.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Long insert(String table_name, String nullColumnHack, ContentValues values)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will insert the record in the table with the values that are passed. The second argument makes sure that no null value is allowed._name\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Int update(String table_name, ContentValues values, String where_clause, String[] where_args )<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will update the a that satisfies the where clause.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Summary<\/h2>\n<p>Finally, in this <strong>Android tutorial<\/strong>, we read about the SQLite in Android. We saw what SQLite is and what are some important features of SQLite. We then went through the reasons we use it in Android. Then we saw its important methods and what their functions are with their brief description.<\/p>\n<p><strong>Thank you and stay tuned with us for more tutorials on Android.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we\u2019ll learn about Android SQLite Database. Till now, we\u2019ve already read the different ways to store the data in Android like internal storage, external storage, and preferences. This technique is a&#46;&#46;&#46;<\/p>\n","protected":false},"author":10,"featured_media":78268,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18722],"tags":[22370,22371],"class_list":["post-78255","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","tag-android-sqlite","tag-sqlite-android"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Android SQLite Database for Android Developers - DataFlair<\/title>\n<meta name=\"description\" content=\"Android SQLite database - Learn what is SQLite in android, Its need, its features that make it so helpful &amp; methods of SQLite\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/android-sqlite\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android SQLite Database for Android Developers - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Android SQLite database - Learn what is SQLite in android, Its need, its features that make it so helpful &amp; methods of SQLite\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/android-sqlite\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-28T06:28:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-22T16:33:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/05\/Android-SQLite-Database.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android SQLite Database for Android Developers - DataFlair","description":"Android SQLite database - Learn what is SQLite in android, Its need, its features that make it so helpful & methods of SQLite","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:\/\/data-flair.training\/blogs\/android-sqlite\/","og_locale":"en_US","og_type":"article","og_title":"Android SQLite Database for Android Developers - DataFlair","og_description":"Android SQLite database - Learn what is SQLite in android, Its need, its features that make it so helpful & methods of SQLite","og_url":"https:\/\/data-flair.training\/blogs\/android-sqlite\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2020-05-28T06:28:41+00:00","article_modified_time":"2024-08-22T16:33:32+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/05\/Android-SQLite-Database.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/android-sqlite\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/android-sqlite\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/a90b082e16aa38d207212d22b0581f33"},"headline":"Android SQLite Database for Android Developers","datePublished":"2020-05-28T06:28:41+00:00","dateModified":"2024-08-22T16:33:32+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/android-sqlite\/"},"wordCount":754,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/android-sqlite\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/05\/Android-SQLite-Database.jpg","keywords":["Android SQLite","SQLite Android"],"articleSection":["Android Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/android-sqlite\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/android-sqlite\/","url":"https:\/\/data-flair.training\/blogs\/android-sqlite\/","name":"Android SQLite Database for Android Developers - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/android-sqlite\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/android-sqlite\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/05\/Android-SQLite-Database.jpg","datePublished":"2020-05-28T06:28:41+00:00","dateModified":"2024-08-22T16:33:32+00:00","description":"Android SQLite database - Learn what is SQLite in android, Its need, its features that make it so helpful & methods of SQLite","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/android-sqlite\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/android-sqlite\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/android-sqlite\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/05\/Android-SQLite-Database.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/05\/Android-SQLite-Database.jpg","width":802,"height":420,"caption":"Android SQLite Database"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/android-sqlite\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Android Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/android\/"},{"@type":"ListItem","position":3,"name":"Android SQLite Database for Android Developers"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/a90b082e16aa38d207212d22b0581f33","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team is passionate about delivering top-notch tutorials and resources on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. With expertise in the tech industry, we simplify complex topics to help learners excel. Stay updated with our latest insights.","url":"https:\/\/data-flair.training\/blogs\/author\/dfadteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/78255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=78255"}],"version-history":[{"count":4,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/78255\/revisions"}],"predecessor-version":[{"id":143220,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/78255\/revisions\/143220"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/78268"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=78255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=78255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=78255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}