New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Creating a new SQLite database

From: Android SDK: Local Data Storage

Video: Creating a new SQLite database

So far in this course, I focused on two major ways of saving data locally in an Android app. I've described how to use shared preferences to store simple key value pairs and how to create and read files in internal and external storage and how to use particular formats such as JSON and XML that are really useful for storing structured but not strongly-typed data. You will find, however, that many Android apps need more power. You might need the ability to store strongly-typed data or the ability to have multiple tables that you can relate to each other at runtime.

Creating a new SQLite database

So far in this course, I focused on two major ways of saving data locally in an Android app. I've described how to use shared preferences to store simple key value pairs and how to create and read files in internal and external storage and how to use particular formats such as JSON and XML that are really useful for storing structured but not strongly-typed data. You will find, however, that many Android apps need more power. You might need the ability to store strongly-typed data or the ability to have multiple tables that you can relate to each other at runtime.

For these purposes, there's nothing like a relational database. Fortunately, the Android SDK incorporates SQLite. SQLite is a very powerful third- party open source database engine. You can find out everything about the raw SQLite product at this website, www.sqlite.org, but everything you really need is included in the Android SDK, including all the libraries that make up the Android engine, all of the classes and interfaces you need to program with it, and all of the documentation.

The classes and interfaces you use in Android to work with SQLite are all in a single package, android.database.sqlite. You can find the documentation at this web page, developer.android.com and so on. Here are the important classes that we'll use when working with an SQLite database. The SQLite Database class represents a database file. Each SQLite database is stored as a single file on your Android persistent storage area.

You can add a file extension of .db if you like, but it's not required. When you create the database, you'll control the name of the file that contains the database, and it will be a single file, unlike some other databases that scatter information over multiple files. All of the other classes in this list will be used for various tasks. The SQLiteOpenHelper is a base class that you'll extend to manage your particular database, and then you'll use classes like SQLite Query and SQLite Statement to represent queries and SQL statements.

You'll use the cursor to loop through the results from a query and SQLite Query Builder to build and manage your queries, and when problems occur, they'll be exposed to you as SQLite exception or subclasses of that class. So in the remaining videos of this chapter and the one after this, I'll describe how to get started with SQLite, how to create your initial database, and then how to manage the database at runtime to contain strongly-typed relational data for your Android app.

Show transcript

This video is part of

Image for Android SDK: Local Data Storage
Android SDK: Local Data Storage

29 video lessons · 5486 viewers

David Gassner
Author

 
Expand all | Collapse all
  1. 6m 34s
    1. Welcome
      50s
    2. What you should know before starting this course
      2m 11s
    3. Using the exercise files
      3m 33s
  2. 21m 6s
    1. Exploring local data storage options
      5m 58s
    2. Configuring Eclipse and the Android Developer Tools
      5m 29s
    3. Creating an Android virtual device
      3m 23s
    4. Creating a new Android project
      6m 16s
  3. 31m 30s
    1. Using preferences in Android apps
      5m 28s
    2. Defining preferences with Java
      9m 31s
    3. Defining shared preferences with an activity
      10m 50s
    4. Listening for changes to shared preferences
      5m 41s
  4. 51m 13s
    1. Creating and reading files in internal storage
      10m 18s
    2. Creating and reading JSON data files
      9m 48s
    3. Working with files in external storage
      11m 22s
    4. Parsing a read-only XML file with XmlPullParser
      11m 46s
    5. Parsing a read-only XML file with JDOM
      7m 59s
  5. 1h 8m
    1. Creating a new SQLite database
      2m 52s
    2. Defining a database with SQLiteOpenHelper
      12m 12s
    3. Managing the database with a DataSource class
      9m 38s
    4. Inserting data into a database table
      10m 29s
    5. Retrieving and displaying data
      11m 44s
    6. Importing data from XML to SQLite
      5m 15s
    7. Filtering and sorting data
      9m 27s
    8. Accessing a database from the command line
      6m 46s
  6. 42m 0s
    1. Improving the data display
      9m 29s
    2. Passing user-selected data to a detail activity
      11m 36s
    3. Working with multiple database tables
      10m 28s
    4. Deleting data from database tables
      10m 27s
  7. 49s
    1. Where to go from here
      49s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.