How can I use OrmLite with Android's default S

2019-05-31 13:50发布

I have a big problem using the default SQLite database via JDBC driver.I would like to use ORMLite with this.Let me expose my code:

String databaseUrl = "jdbc:sqlite:/data/data/my.package.name/db.sqlite";

Class.forName("SQLite.JDBCDriver");
DriverManager.getConnection(databaseUrl);

dataSource = DatabaseTypeUtils.createSimpleDataSource(databaseUrl);
databaseType = DatabaseTypeUtils.createDatabaseType(dataSource);
databaseType.loadDriver();

UpDao = new UserProfileJdbcDao(databaseType);
UpDao.setDataSource(dataSource);
UpDao.initialize();

I downloaded the ormlite2.8.jar (src) and modified the SqliteDatabaseType class so that the private final static String DRIVER_CLASS_NAME = "SQLite.JDBCDriver" . However when I imported all of the classes from the ormlite2.8.jar(src) , I found errors concerning the logger, specifically the CommonsLoggingLog and Log4jLog classes.Someone advised my to write my own Logger class that uses the Android logger , but I do not know how to do that. This is the ORMLite I am using for Android : http://ormlite.sourceforge.net/sqlite_java_android_orm.html

I am highly appreciating any help. Thank you in advance.

Regads, Andrew

2条回答
小情绪 Triste *
2楼-- · 2019-05-31 13:59

This is an old question Andrew, but for posterity, ORMLite has native support for the Android OS database calls. I'd recommend upgrading and trying it out. There are sample projects, documentation, and downloads here:

http://ormlite.com/sqlite_java_android_orm.shtml

查看更多
可以哭但决不认输i
3楼-- · 2019-05-31 14:06

In the documentation of ORMlite is mentioned, that there are no direct dependencies and Log4J will be only used if provided in the class path.

Are you sure, that importing the complete code is the right way using ORMlite?

What about that: http://ormlite.sourceforge.net/javadoc/doc-files/ormlite_5.html#SEC25 You should do whats mentioned in the first sentence:

DatabaseType databaseType = new SqliteAndroidDatabaseType();
databaseType.loadDriver();
// change this for your path and application name
String databaseUrl = "jdbc:" + databaseType.getDriverUrlPart() + ":" +
    getFilesDir() + "/test.db";
SimpleDataSource dataSource =
    DatabaseTypeUtils.createSimpleDataSource(databaseUrl);

// configure and use your dao as in previous examples
查看更多
登录 后发表回答