简体   繁体   English

Android ORMLite,使用预先填充的数据库并使用它

[英]Android ORMLite, use pre-populated database and use it

I have a pre-populated database, I hadd .csv and make a database in sqllite manager and imported all values into this database. 我有一个预先填充的数据库,我拥有.csv并在sqllite管理器中创建了一个数据库,并将所有值导入了该数据库。

Now I put this database into android's assets folder and want to use this via ORMLite in my android application. 现在,我将此数据库放入android的资产文件夹,并希望通过我的android应用程序中的ORMLite使用它。

Please, need your help and will be thankful to you. 请,需要您的帮助,将感谢您。

Now I put this database into android's assets folder and want to use this via ORMLite in my android application. 现在,我将此数据库放入android的资产文件夹,并希望通过我的android应用程序中的ORMLite使用它。

Boy there is a lot of ground to cover here to use ORMLite with this. Boy在这里有很多基础可以使用ORMLite

The short answer is that you will need to create Java objects which correspond to your database tables. 简短的答案是,您将需要创建与数据库表相对应的Java对象。 Each Java object should have fields that match the table columns with the appropriate types with @DatabaseField annotations. 每个Java对象都应具有与带有@DatabaseField批注的适当类型的表列匹配的字段。

For example, if you CSV file was: 例如,如果您的CSV文件是:

# name, id, street
Bill Jones,123,131 Main St.

and your table created is something like: 您创建的表如下所示:

create table user (name VARCHAR(255), integer id, street VARCHAR(255));

The Java object you will need is something like: 您将需要的Java对象类似于:

public class User {
   @DatabaseField(id = true)
   int id;
   @DatabaseField
   String name;
   @DatabaseField
   String street;
}

Then you would use ORMLite to read in objects from your database. 然后,您将使用ORMLite从数据库中读取对象。 You should see the ORMLite home page and the Getting Started section of the documentation. 您应该看到ORMLite主页和文档的“入门”部分。 For linking up with the existing database, you should read the section of the manual about using with Android. 要链接到现有数据库,您应该阅读手册中有关与Android一起使用的部分。

Any additional questions I'd ask to the ORMLite Users Mailing List . 我想向ORMLite用户邮件列表提出任何其他问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM