DatabaseConnector Constructor and Methods open and close
DatabaseConnection
’s constructor (Fig. 8.52, lines 22–27) creates a new object of class DatabaseOpenHelper
(Fig. 8.58), which will be used to open or create the database. We discuss the details of the DatabaseOpenHelper
constructor in Fig. 8.58. The open
method (lines 30–34) attempts to establish a connection to the database and throws a SQLException
if the connection attempt fails. Method getWritableDatabase (line 33), which is inherited from SQLiteOpenHelper
, returns a SQLiteDatabase
object. If the database has not yet been created, this method will create it; otherwise, the method will open it. Once the database is opened successfully, it will be cached by the operating system to improve ...
Get Android™ How to Program, Second Edition 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.