ORMLiteORM持久層框架
ORMLite是一個(gè)輕量級的Java對象關(guān)系映射持久層框架。支持包括 MySQL、Postgres、Microsoft SQL Server、H2、Derby、HSQLDB和Sqlite等在內(nèi)的數(shù)據(jù)庫。提供靈活的QueryBuilder來構(gòu)建復(fù)雜的數(shù)據(jù)查詢。強(qiáng)大的抽象DAO類,只需5行代碼便能夠自動生成SQL來創(chuàng)建和刪除數(shù)據(jù)庫表格。
示例代碼:
public class AccountApp {
public static void main(String[] args) throws Exception {
// this uses h2 by default but change to match your database
String databaseUrl = "jdbc:h2:mem:account";
// create a connection source to our database
ConnectionSource connectionSource = new JdbcConnectionSource(databaseUrl);
// instantiate the dao
AccountDaoImpl accountDao = new AccountDaoImpl(connectionSource);
// if you need to create the 'accounts' table make this call
TableUtils.createTable(connectionSource, Account.class);
