// you get the SQLiteOpenHelper from your Android Activity
ConnectionSource connectionSource =
new AndroidConnectionSource(sqliteOpenHelper);
// instantiate the DAO to handle Account with String id
Dao<Account,String> accountDao =
BaseDaoImpl.createDao(connectionSource, Account.class);
// if you need to create the 'accounts' table make this call
TableUtils.createTable(connectionSource, Account.class);
// create an instance of Account
String name = "Jim Smith";
Account account = new Account(name, "_secret");
// persist the account object to the database
// it should return 1 for the 1 row inserted
if (accountDao.create(account) != 1) {
throw new Exception("Failure adding account");
}
// retrieve the account
Account account2 = accountDao.queryForId(name);
// show its password
System.out.println("Account: " + account2.getPassword());
// close the connection source
connectionSource.close();
1.ormLite例子:// you get the SQLiteOpenHelper from your Android ActivityConnectionSource connectionSource = new AndroidConnectionSource(sqliteOpenHelper);// instantiate the DAO to handle Acc