android ormlite简单使用和读取sdcard下db数据库

废话不多说:

1、从http://ormlite.com/releases/点击打开链接版本库下载最新的core和android的jar包,放入你的android工程中

2、使用以下方法得到DAO对象

/**
	 * DAO对象的使用参见OrmLite的API
	 */
	public Dao<T, String> createBeaconTable(String buildId,
			String floor) {
		try {

			// 使用SQLiteDatabase创建或者打开sd或者assets下的db文件
			DTFileUtils.createDirs(DTFileUtils.getDataDir() + buildId
					+ File.separator);
			SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(
					DTFileUtils.getDataDir() + buildId + File.separator
							+ buildId + "_" + floor + ".db", null);
			// ORMLite的android.jar封装SQLiteDatabase
			AndroidConnectionSource connectionSource = new AndroidConnectionSource(
					db);

			/**
			 * 以下为官方首页快速使用方式,没有任何改动的照搬,由于需要ConnectionSource对象,
			 * 通过查看API发现子类AndroidConnectionSource
			 */

			// instantiate the DAO to handle Account with String id
			Dao<T, String> accountDao = DaoManager.createDao(
					connectionSource, T.class);

			// if you need to create the 'accounts' table make this call
			TableUtils.createTableIfNotExists(connectionSource,
					T.class);

			// create an instance of Account
			// connectionSource.close();
			return accountDao;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值