0

I'm using ORMlite in my Android app.

However, I am pre-populating the database at build time. This happens in a J2SE program.

To deal with SQL in J2SE I am using sqlite4java

In order to get a Dao in ORMlite, I need a com.j256.ormlite.support.ConnectionSource.

How can I get a ConnectionSource that uses the sql4java database?

GaRRaPeTa
  • 5,459
  • 4
  • 37
  • 61

1 Answers1

0

I got it.

ORMLite can access a SQLite database using a JDBC Connection.

For this you need:

http://ormlite.com/releases/4.48/ormlite-jdbc-4.48.jar which is a jar to allow ORMLite to connect to the DB using JDBC

and

https://bitbucket.org/xerial/sqlite-jdbc which is a JDBC driver to connect to sqllite databases

// this loads the JDBC driver to access a sqlite db with jdbc
// http://stackoverflow.com/questions/6740601/what-does-class-fornameorg-sqlite-jdbc-do
Class.forName("org.sqlite.JDBC");

// this uses a specific driver to access sqlite db via jdbc
String dbConnectionString = "jdbc:sqlite:/pathToTheDataBase/database.db";
ConnectionSource connectionSource = new JdbcConnectionSource(dbConnectionString);

// create table using ORMLIte
TableUtils.createTable(connectionSource, UserEntity.class);

Dao<UserEntity,String> accountDao = DaoManager.createDao(connectionSource, UserEntity.class);

....

}

GaRRaPeTa
  • 5,459
  • 4
  • 37
  • 61