Working with SQLite databases
Once you have created an SQLite database, you can use SQL statements to add data, retrieve data, and modify the database.
The list of supported SQL statements and their syntax is available on the SQLite web site. The Database API does not support the following SQLite statements: ATTACH DATABASE, DETACH DATABASE, and PRAGMA. In addition, FTS2 and RTREE are not supported.
The following steps outline the basic procedure for running statements:
- Create an SQL statement by invoking Database.createStatement().
- Prepare the statement to run by invoking Statement.prepare().
- Run the statement. If the statement might return results, run it by invoking Statement.getCursor(). Otherwise, use Statement.execute().
- If the statement returns a result set, retrieve the result set by iterating over the returned cursor row by row. Do this using the Cursor interface, which works in all circumstances but is forward-only. For birectional cursor movement, but only for small result sets, use the BufferedCursor class.
- Using transactions
- Using SQL parameters
- Using foreign key constraints
- Code sample: Inserting table data
- Code sample: Retrieving table data
- Code sample: Deleting table data
- Code sample: Updating table data
- Code sample: Listing database tables
Next topic: Using transactions
Previous topic: Code sample: Deleting an SQLite database