java:为什么 ResultSet 不可序列化? [英] java: Why ResultSet is not Serializable?

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

问题描述

经过数小时的搜索,我终于意识到 java.sql.ResultSet 不是可序列化的,也没有办法做到这一点.我尝试添加到列表中,作为 Serializable 对象和其他东西中的实例变量,但结果是天真和绝望的尝试.我尝试使用 RowSet 的实现,例如CachedRowSetImpl它们是可序列化的,但它们增加了响应时间,很可能是因为它们迭代了 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 不可序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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