有没有办法使用ORMLite打开预先填充的sqlite数据库。我确信有,但我的下一个问题是我应该使用以下代码行吗?
/**
* This is called when the database is first created. Usually you should call createTable statements here to create
* the tables that will store your data.
*/
@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
try {
Log.i(DatabaseHelper.class.getName(), "onCreate");
TableUtils.createTable(connectionSource, Comment.class);
TableUtils.createTable(connectionSource , Words.class);
} catch (SQLException e) {
Log.e(DatabaseHelper.class.getName(), "Can't create database", e);
throw new RuntimeException(e);
}
任何帮助都将不胜感激。
答案 0 :(得分:0)
有没有办法使用ORMLite打开预先填充的sqlite数据库。
要使用现有数据库,您需要精确匹配当前架构才能使其正常工作。您还可以增加数据库版本并使用onUpgrade(...)
方法调整数据库以使其与您的ORMLite实体匹配。
我确信有,但我的下一个问题是我应该使用以下代码行吗?
调用onCreate(...)
方法创建新表(如果它们尚不存在)。要打开现有数据库(就像您提到的主题一样),系统不会调用onCreate(...)
方法。