将 Java 对象添加到数据库

发布于 2024-07-14 18:20:12 字数 136 浏览 2 评论 0原文

对于一项大学作业,我被分配了一个奖品对象,其中包含文本、图像或视频内容。 我想将此信息保存到 Apache Derby 数据库(将在低功率 PDA 上运行)内的 BLOB 字段中。 我怎样才能将这些数据添加到数据库中?

提前致谢。

For a university assignment I have been assigned I have a Prize object which contains either text, image, or video content. I would like to persist this information into a BLOB field within an Apache Derby database (which will be running on a low powered PDA). How can I add this data to the database?

Thanks in advance.

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

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

发布评论

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

评论(5

风为裳 2024-07-21 18:20:12

在本文中使用 Derby 管理非结构化数据的五个步骤
您可以阅读如何执行此操作。

它描述了如何使用 JDBC 将二进制数据插入到 Apache Derby 中具有 BLOB 数据类型的列中。

In this article Five Steps to Managing Unstructured Data with Derby
you can read how to do this.

It describes how to insert binary data into a column with the BLOB datatype in Apache Derby using JDBC.

听不够的曲调 2024-07-21 18:20:12

我假设您将通过 JDBC 进行连接。 如果是这样,只需编写 SQL 并查看PreparedStatement 的 setBlob 方法即可。 应该很简单。

I assume you'll be connecting via JDBC. If so, simply write your SQL and look at the setBlob method of a PreparedStatement. Should be pretty straightforward.

泪之魂 2024-07-21 18:20:12

序列化是最简单的方法,但是如果可能的话你可以它看起来像一个真实的数据库表,其结构包含id(bigint)datatype(smallint)creationdate(date)data (blob) 并专门让客户端代码将对象的数据保存在那里。 通过这种方式,您可以进行诸如“获取 2008 年 1 月 1 日至 2009 年 1 月 15 日期间创建的所有视频奖品”之类的搜索,并且如果您的类更改太多而导致序列化停止,它也不会破坏旧数据在职的。

如果将来有需要的话,这种解决方案也很容易扩展; 我知道这是一项学校作业,这种需求很可能永远不会出现,但如果你的老师/教授了解他的知识,我敢打赌他愿意为以这种方式进行这项练习额外加一两分,因为这需要一点时间更多的时间,并表明您可以采取措施提前做好准备,以应对不断变化的软件开发环境。

Serialization is the easy way to do it, however if possible you could make it look like a real database table with a structure containing id (bigint), datatype (smallint), creationdate (date) and data (blob) and specifically make the client code to save the object's data there. This way you could do searches like "get all video prizes created between January 1st 2008 and January 15th 2009" and it wouldn't break down old data if your class would change too much for the serialization to stop working.

This sort of solution would be easy to extend in the future too if there would be need for it; I understand this is a school assignment and such need most likely won't ever surface but if your teacher/professor knows his stuff, I bet he's willing to give an extra point or two for doing this excercise in this way since it takes a bit more time and shows that you can take the steps to prepare in advance for coping in the everchanging landscape of software development.

尐籹人 2024-07-21 18:20:12

如果您使用 Netbeans(我假设 Eclipse 具有类似的功能),您可以设置数据库模式并从数据库创建新的 Java 实体类,它将为您生成适当的 JPA 类。

http://hendrosteven.wordpress.com/2008 /03/06/simple-jpa-application-with-netbeans/

这很好,因为它允许您专注于代码而不是数据库粘合代码。

If you are using Netbeans (I assume Eclipse has similar functionality) you can setup your database schema and the create new Java entity classes from the database and it will generate the appropriate JPA classes for you.

http://hendrosteven.wordpress.com/2008/03/06/simple-jpa-application-with-netbeans/

This is nice as it allows you to focus on your code rather than the database glue code.

微凉徒眸意 2024-07-21 18:20:12

最好的解决方案是使用 Derby,因为它一直是通过 Java 开发的多平台应用程序。

The best solution , is to use Derby, because it keep being a multi platform app developed via Java.

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