首页 \ 问答 \ java:为什么ResultSet不是Serializable?(java: Why ResultSet is not Serializable?)

java:为什么ResultSet不是Serializable?(java: Why ResultSet is not Serializable?)

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

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


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.

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?


原文:
更新时间:2021-12-01 12:12

最满意答案

函数quote_literalquote_nullable可能很有用。 但请注意,这些是PostgreSQL函数,因此请确保DBLINK的另一端了解结果。

您可能还会看一下这部分文档:

http://www.postgresql.org/docs/9.1/interactive/plpgsql-statements.html#PLPGSQL-QUOTE-LITERAL-EXAMPLE

编辑

quote_xyz不能应用于rsocial的用法,而应用于dblink_exec

  SELECT dblink_exec ('dbname=xxx user=xxx password=xxxxx',
                      'INSERT INTO BillingDataUpdate (client_id, columnsupdate) '
                       || 'VALUES (' || quote_nullable(NEW.idclient) || ', ' 
                       || quote_nullable(columnsUpdate) || ');');

请注意字符串连接中更改的'数量。


The functions quote_literal and quote_nullable might be useful. But beware, that these are PostgreSQL functions, so make sure the other side of the DBLINK understands the result.

You might also take a look at this part of the docs:

http://www.postgresql.org/docs/9.1/interactive/plpgsql-statements.html#PLPGSQL-QUOTE-LITERAL-EXAMPLE

EDIT

The quote_xyz must not be applied to the usages of rsocial but to the dblink_exec.

  SELECT dblink_exec ('dbname=xxx user=xxx password=xxxxx',
                      'INSERT INTO BillingDataUpdate (client_id, columnsupdate) '
                       || 'VALUES (' || quote_nullable(NEW.idclient) || ', ' 
                       || quote_nullable(columnsUpdate) || ');');

And please note the changed number of ' in the string concatenation.

相关问答

更多
  • 美元符号用于美元报价 , 对功能定义绝对不具体 。 它可以用于在SQL脚本中几乎任何地方替换单引号。 一个函数的正文恰好是一个字符串文字,必须用单引号括起来。 美元引用是一个PostgreSQL专用的单引号替代,以避免在函数体内引用问题。 您也可以使用单引号来编写函数定义。 但是,您必须逃脱身体中的所有单引号: CREATE OR REPLACE FUNCTION check_phone_number(text) RETURNS boolean AS ' BEGIN IF NOT $1 ~ e''^\ ...
  • 使用any(array[...]) : select * from tblname where tbl_col like any(array['%hello%', '%postgresql%', '%stackoverflow%']); Use any(array[...]): select * from tblname where tbl_col like any(array['%hello%', '%postgresql%', '%stackoverflow%']);
  • 您正尝试从tableName vaiable存储的文本中进行SELECT 。 你不能这样做,因为Postgres认为你希望他从名为tableName表中选择,但可能这样的表不存在。 您需要在字符串中创建动态查询并使用EXECUTE ... INTO ...语句 。 喜欢这个: DECLARE query TEXT; ... query := 'SELECT 100 - (count(' || _name::TEXT || ') * 100) / count(*) FROM ' || ...
  • PERFORM是用于调用void函数的plpgsql命令。 PLpgSQL非常小心无用的SELECT语句 - 不带INTO子句的SELECT语句是不允许的。 但有时你需要调用一个函数,而且你不需要存储结果(或者函数没有任何结果)。 SQL的函数用SELECT语句调用。 但在PLpgSQL中不可能 - 所以引入了PERFORM命令。 CREATE OR REPLACE FUNCTION foo() RETURNS void AS $$ BEGIN RAISE NOTICE 'Hello from void ...
  • 可能的解决方法 :使用子块 : DO $do$ << main >> DECLARE dummy CONSTANT text; -- without assingment it's just NULL myvar text; BEGIN RAISE NOTICE 'dummy is >>%<<', dummy; -- -- dummy := 'foo'; -- would raise exception! SELECT INTO myv ...
  • 这对我有用: Connection con = DriverManager.getConnection("jdbc:postgresql://localhost/postgres", "...", "******"); Statement stmt = con.createStatement(); String create = "create function the_answer() \n" + "returns integer as $$\n" + "begin \n" + " ...
  • 是的 ,可以做到: CREATE OR REPLACE FUNCTION f_value_cursor(_curs refcursor, _id1 int, _id2 int) RETURNS TABLE (col1 int, col2 text) AS $func$ DECLARE var_x text := (SELECT t.col2 FROM tbl t WHERE t.tbl_id = _id1); BEGIN OPEN _curs FOR SELECT var_x; RETURN ...
  • 问题是在someFunction()解释了problematicVariable这个名称 ,它显然没有被定义。 因为这是一个稳定的调用(函数参数总是相同所以每次调用都会从函数返回相同的数据,假设不依赖于volatile值)你最好把它从循环中取出并重复调用someF()与第一个函数调用的结果。 CREATE OR REPLACE FUNCTION someF(a integer, b integer, c integer) RETURNS someType AS $$ DECLARE problema ...
  • 变量schedule_ids是一个数组,您应该使用array_agg()为其分配一个数组值。 接下来,使用ANY (array expression)而不是IN运算符: block.schedule_ids := (select array_agg(distinct c."schedule_id") from "slot_task" as st join "slot" as s on s."slot_id" = st ...
  • 函数quote_literal和quote_nullable可能很有用。 但请注意,这些是PostgreSQL函数,因此请确保DBLINK的另一端了解结果。 您可能还会看一下这部分文档: http://www.postgresql.org/docs/9.1/interactive/plpgsql-statements.html#PLPGSQL-QUOTE-LITERAL-EXAMPLE 编辑 quote_xyz不能应用于rsocial的用法,而应用于dblink_exec 。 SELECT dblink ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。