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?
原文:
最满意答案
函数
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_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
andquote_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 ofrsocial
but to thedblink_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''^\ ...
-
PL / PGSQL动态在哪里(PL/PGSQL Dynamic Where)[2023-04-12]
使用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%']); -
调试PL / pgSQL函数(Debugging a PL/pgSQL function)[2023-05-15]
您正尝试从tableName vaiable存储的文本中进行SELECT 。 你不能这样做,因为Postgres认为你希望他从名为tableName表中选择,但可能这样的表不存在。 您需要在字符串中创建动态查询并使用EXECUTE ... INTO ...语句 。 喜欢这个: DECLARE query TEXT; ... query := 'SELECT 100 - (count(' || _name::TEXT || ') * 100) / count(*) FROM ' || ... -
PL / pgSQL执行与执行(PL/pgSQL perform vs execute)[2022-12-01]
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 ...
-
PL / pgSQL:不能在`in`运算符的右侧使用变量(PL/pgSQL : can't use variable on the right side of `in` operator)[2023-06-21]
变量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 ... -
转义PL / pgSQL变量(Escape an PL/pgSQL variable)[2023-12-10]
函数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 ...