java:为什么ResultSet不是Serializable? [英] java: Why ResultSet is not Serializable?

查看:105
本文介绍了java:为什么ResultSet不是Serializable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过几个小时的搜索,我终于意识到 java。 sql.ResultSet 不是Serializable,也没有办法做到这一点。我尝试添加到List,作为Serializable对象中的实例变量和其他东西,但事情结果是天真和绝望的尝试。我试图使用 RowSet 的实现 CachedRowSetImpl 这是Serializable但它们会增加响应时间,很可能是因为它们迭代ResultSet。
底线,除非您选择迭代ResultSet,否则您无法通过网络发送它包含的数据。

After hours of search I finally realized that java.sql.ResultSet is not Serializable neither there's a way to do that. I tried adding to a List, as an instance variable in a Serializable object and other stuff but things turned out to be naive and desperate attempts. I tried to uses the implementations of RowSet like CachedRowSetImpl that are Serializable but they increase the response time, most probably because they iterate the ResultSet. Bottom line, until or unless you choose to iterate ResultSet, you can't send the data it contains over a network.

我知道我的替代方案必须迭代并将内容添加到数据模型对象和列表中,但我绝望地想知道这背后的理性是什么?当时java的开发人员想到了什么?

I know the alternatives that I must iterate and add contents to a data model object and a list but I desperatly want to know what is the rational behind this? What do the developers of java thought at that time?

推荐答案

据我所知,ResultSet没有包含数据。
如果你打电话给 http://docs.oracle .com / javase / 7 / docs / api / java / sql / ResultSet.html#next() ResultSet将从底层(JDBC)连接到数据库获取数据。

As far as I know the ResultSet does not "contain" the data. If you call http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html#next() the ResultSet will get the data from the underlying (JDBC) connection to the database.

如果ResultSet是序列化并转移到另一台计算机,那么这是不可能的。连接将无法使用。

This would be impossible, if the ResultSet was i.e. serialized and transferred to a different computer. There the connection would be unavailable.

这篇关于java:为什么ResultSet不是Serializable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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