Creating a Database and Its Tables
As you’ve seen, you can create a database by using the SQLiteOpenHelper
class. The methods of this class are called automatically by Android whenever the database needs to be created or updated.
You create the database file by calling the constructor of SQLiteOpenHelper
, passing the database name and database version. The database is stored by default in the /data/data/APPLICATION_NAME/databases
directory. In your application the database will be created at /data/data/com.androiddevbook.onyourbike.chapter5/databases/OnYourBike.db
.
To create the database tables themselves, you need to use SQL. The SQL to create a table takes this form:
create table <tablename> ( <fieldname> <datatype>, ...
Get Learning Android™ Application Programming: A Hands-On Guide to Building Android Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.