基本的 ORMLite 数据库问题

发布于 2024-10-20 18:18:40 字数 164 浏览 0 评论 0原文

对于 ORMLIte 网站 上列出的示例,我有两个问题。

  • 数据库放在哪里以及如何导入?
  • 我应该将 DAO 和连接工厂放在哪个类中?

I have two questions about the examples listed on the ORMLIte website.

  • Where do I put the database and how do I import it?
  • Which class do I put the DAO and the connection factory in?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅唱々樱花落 2024-10-27 18:18:40

我将数据库放在哪里以及如何导入它。

你是指 h2 jar 文件吗?如入门文档(1.4代码示例)中所述,您需要将h2 jar文件添加到类路径中。如果您不确定如何设置类路径,请先研究一下,因为这是 Java 中非常重要的概念。

Where do I put the database and how do I import it.

Do you mean the h2 jar file? As described in the getting started document (1.4 Code Example), you need to add the h2 jar file to the class path. If you are not sure how to set the class path, please investigate that first, because that's a very important concept in Java.

那伤。 2024-10-27 18:18:40

您必须使用注释创建数据库模型
@DatabaseTable()

@DatabaseField()

类似:

@DatabaseTable(tableName="YOUR_TABLE_NAME")
public class SimpleDataModel {
    @DatabaseField(id=true)
    private int idSimpleData;
    @DatabaseField()
    private String NameSomeDataHere;
}

您不必导入它,只需创建一个扩展为 ORMSqliteOpenHelper 的 Helper 类。

它有很好的文档,只需在 ORMLite 站点上搜索一下即可。但一个例子是:

public class dbHelper extends ORMSqliteOpenHelper {
    onCreate() { // I'm letting some code behind, as long as Eclipse do implement methods for you. ;)
        TableUtils.CreateTable(connectionSource, SimpleDataModel.class);
        //This one above is what is going to create your tables.
        //Afterwards you have to use DAO's to access your data, os it's nonsense.
        //So if you're a begginner at android just read the ENTIRE documentarion of ORMLite, and MAYBE you'll understand something ;P        

}

You have to create the database Models with the annotations
@DatabaseTable()

and

@DatabaseField()

Like:

@DatabaseTable(tableName="YOUR_TABLE_NAME")
public class SimpleDataModel {
    @DatabaseField(id=true)
    private int idSimpleData;
    @DatabaseField()
    private String NameSomeDataHere;
}

You don't have to import it, just create a Helper class with extends to ORMSqliteOpenHelper.

It's pretty well documented, just search a bit at ORMLite site. But an example is:

public class dbHelper extends ORMSqliteOpenHelper {
    onCreate() { // I'm letting some code behind, as long as Eclipse do implement methods for you. ;)
        TableUtils.CreateTable(connectionSource, SimpleDataModel.class);
        //This one above is what is going to create your tables.
        //Afterwards you have to use DAO's to access your data, os it's nonsense.
        //So if you're a begginner at android just read the ENTIRE documentarion of ORMLite, and MAYBE you'll understand something ;P        

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文