[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7. Example Code

Here is some example code to help you get going with ORMLite. I often find that code is the best documentation of how to get something working. Please feel free to suggest additional example packages for inclusion here. Source code submissions are welcome as long as you don’t get piqued if we don’t chose your’s.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.1 JDBC Examples

All of the JDBC examples below depend on the H2 database which is a native Java SQL implementation. You can download the latest jar from the website.

Simple, basic

This is a simple application which performs database operations on a single class/table. See the source code.

Foreign objects

This example shows how to use foreign objects. See section Foreign Object Fields. See the source code.

Foreign collections

This example shows how to use foreign collections. See section Foreign Collections. See the source code.

Field configuration

This example shows how you can configure a class in ORMLite using Java code instead of annotations. See section Class Configuration. See the source code.

Many to many

This example is a bit more complicated with multiple tables and is designed for folks trying to model a many-to-many relationship. It has a join-table, foreign fields, and also utilizes inner queries. See the source code.

Spring wiring

To demonstrate how to use Spring wiring with ORMLite, this little program includes classes and XML configuration files. See the source code.

Data persister

This example shows how to define custom data persisters with ORMLite which can change how data types are stored in the database. See the source code.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.2 Android Examples

For Android developers, here some complete example application projects to help you get started. See here for tarballs of all of the packages as well as code links.


A basic Android application which does some database operations and then quits.


A nice little application written by Kevin G. that provides a counter type application using ORMLite.


An example of a service application that uses ORMLite written by Kevin G.


This is similar to the HelloAndroid example but it is using JDBC and H2 instead of the build-in Android database calls. This is more a proof of concept rather than a true example. The wiring for the onCreate and onUpdate is a hack. H2 is certainly larger, has tons more features, but is slower than the native SQLite. Also, JDBC under Android is not completely sanctioned by Google and support for it may be removed in the future.


This is similar to the HelloAndroid example but its activity does not extend the OrmLiteBaseActivity but instead manages the helpers itself. Certain programmers may want to manage the database connections using their own code to better share between activities and services or to use ORMLite when it is not possible to extend the base classes.


This is similar to the HelloAndroid example but it uses two separate databases, manages the helpers itself, and does not use the OpenHelperManager to manage the helpers at all. This is one way that you can deal with two different databases.

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Gray Watson on February 19, 2018 using texi2html 1.82.