如何存储对象SQLite数据库? [英] How to store object in sqlite database?

查看:320
本文介绍了如何存储对象SQLite数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时可以存储用户定义的对象从Android的SQLite数据库?例如:我创建了一个班,我想在数据库中存储的类对象。可能吗?如果是,如何进行?在黑莓平台上,我可以直接在持久对象存储对象。是否有可能使用SQLite和Android这样做呢?

Is it possible to store user defined objects in a SQLite database from Android? For example: I am creating one class and I want to store that class object in the database. Is it possible? If it is, how to proceed? On the Blackberry platform, I am able to store objects directly in persistent objects. Is it possible to do this with SQLite and Android?

推荐答案

您需要能够将您的对象序列化到一个字节流,然后从字节流中重新创建对象。

You'll need to be able to serialize your object into a byte stream and then recreate your object from a byte stream.

然后,只需存储字节流在你的数据库。

Then, just store that byte stream in your db.

编辑: 阅读这篇文章了解序列化的Java。它迎合了在一个更好的方法这个问题比我将能够通过只给一些code片段。

Read this article to learn about serialization in Java. It caters to the subject in a much better way than I would be able to by just giving some code snippets.

这篇关于如何存储对象SQLite数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆