栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Java中从PostgreSQL访问返回setof refcursor的程序?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Java中从PostgreSQL访问返回setof refcursor的程序?

returns setof refcursor
表示您在调用时得到一个常规
ResultSet
,其中每个“行”包含 另一个 ResultSet
getObject()

以下对我有用:

ResultSet rs = stmt.executeQuery("select * from usp_sel_article_initialdata_new1()");if (rs.next()){  // first result set returned  Object o = rs.getObject(1);  if (o instanceof ResultSet)  {    ResultSet rs1 = (ResultSet)o;    while (rs1.next())    {       int id = rs1.getInt(1);       String name = rs1.getString(2);       .... retrieve the other columns using the approriate getXXX() calls    }  }}if (rs.next()) {  // process second ResultSet   Object o = rs.getObject(1);  if (o instanceof ResultSet)  {    ResultSet rs2 = (ResultSet)o;    while (rs2.next())    {       ......    }  }}

从内部

psql
您也可以使用,
select * from usp_sel_article_initialdata_new1()
您只需要在
FETCHALL
以后使用即可。有关示例,请参见手册:http : //www.postgresql.org/docs/current/static/plpgsql-
cursors.html#AEN59018

postgres=> select * from usp_sel_article_initialdata_new1(); usp_sel_article_initialdata_new1---------------------------------- <unnamed portal 1> <unnamed portal 2>(2 rows)postgres=> fetch all from "<unnamed portal 1>"; ?column?----------        1(1 row)postgres=> fetch all from "<unnamed portal 2>"; ?column?----------        2(1 row)postgres=>

(我为上面的示例创建了一个虚拟函数,该函数仅返回一行包含

1
第一个游标和
2
第二个游标的值)

编辑

为了使其正常工作,它需要在事务内部运行。因此,必须关闭自动提交:

connection.setAutoCommit(false);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/410443.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号