基本的 ORMLite 数据库问题
对于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你是指 h2 jar 文件吗?如入门文档(1.4代码示例)中所述,您需要将h2 jar文件添加到类路径中。如果您不确定如何设置类路径,请先研究一下,因为这是 Java 中非常重要的概念。
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.
您必须使用注释创建数据库模型
@DatabaseTable()
和
@DatabaseField()
类似:
您不必导入它,只需创建一个扩展为 ORMSqliteOpenHelper 的 Helper 类。
它有很好的文档,只需在 ORMLite 站点上搜索一下即可。但一个例子是:
You have to create the database Models with the annotations
@DatabaseTable()
and
@DatabaseField()
Like:
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: