【问题标题】:Is it possible to use ORMLite with sqlite4java?是否可以将 ORMLite 与 sqlite4java 一起使用?
【发布时间】:2014-07-10 07:57:47
【问题描述】:

我在我的 Android 应用中使用 ORMlite

但是,我在构建时预先填充了数据库。这发生在 J2SE 程序中。

为了处理 J2SE 中的 SQL,我使用 sqlite4java

为了在 ORMlite 中获得一个 Dao,我需要一个 com.j256.ormlite.support.ConnectionSource。

如何获得使用 sql4java 数据库的 ConnectionSource?

【问题讨论】:

    标签: java android sqlite ormlite


    【解决方案1】:

    我明白了。

    ORMLite 可以使用 JDBC 连接访问 SQLite 数据库。

    为此,您需要:

    http://ormlite.com/releases/4.48/ormlite-jdbc-4.48.jar 这是一个允许 ORMLite 使用 JDBC 连接到数据库的 jar

    https://bitbucket.org/xerial/sqlite-jdbc 这是一个连接到 sqllite 数据库的 JDBC 驱动程序

    // 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);
    
    ....
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-12
      • 2016-04-01
      • 2011-01-20
      • 2018-08-11
      • 2021-08-05
      • 2019-03-18
      • 2014-03-15
      • 2021-03-31
      相关资源
      最近更新 更多