在 (Liberty) Batch 块步骤中,获取“ResultSet is closed"从步骤前面发出的数据库查询中滚动 ResultSet 时 [英] In a (Liberty) Batch chunk step, getting "ResultSet is closed" when scrolling through ResultSet from database query issued earlier in the step

查看:20
本文介绍了在 (Liberty) Batch 块步骤中,获取“ResultSet is closed"从步骤前面发出的数据库查询中滚动 ResultSet 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 DB2 表中读取数据并将其转储到文件中.

I am reading data from DB2 table and dumping it into a file.

我在块侦听器的 beforeChunk() 中执行我的简单选择查询,并使用步骤上下文在 itemreader 中获取它.

I execute my simple select query in the chunk listener's beforeChunk() and use the step context to get it in itemreader.

在块中,我将检查点策略设置为 item,itemcount 设置为 5.

In the chunk i set the checkpoint policy as item and itemcount as 5.

输出是被反复读写的前 5 条记录.

在这个 IBM 网站上的示例 java 批处理代码中,它们具有开始和结束参数查询.

In this sample java batch code from IBM's site they have start and end parameters in the query.

查询中是否需要有开始和结束参数?有没有其他方法可以确保当查询再次运行时,它会一次又一次地读取下一个数据块而不是同一个数据块?

Is it necessary to have start and end parameters in your query? Is there no other way to make sure that when the query is run again it reads the next chunk of data and not the same chunk again and again?

我在 WebSphere Liberty 上使用 IBM 的 JSR 352 实现

I am using IBM's implementation of JSR 352 on WebSphere Liberty

推荐答案

尝试将数据源配置为使用不可共享连接.

如果您遵循此示例,您将看到它使用较旧的部署描述符 XML 文件.您可以编辑 batch-bonuspayout-application/src/main/webapp/WEB-INF/web.xml 以添加以下行:

Try configuring the datasource to use unshareable connections.

If you are following this sample, you'll see it uses the older deployment descriptor XML files. You can edit batch-bonuspayout-application/src/main/webapp/WEB-INF/web.xml to add the line:

<res-sharing-scope>Unshareable</res-sharing-scope>

所以你将拥有:

<web-app id="BonusPayout" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
  <display-name>BonusPayout</display-name>
  <description>This is the BonusPayout sample.</description>
  <resource-ref>
    <description>Bonus Payout DS</description>
    <res-ref-name>jdbc/BonusPayoutDS</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Unshareable</res-sharing-scope>
  </resource-ref>
</web-app>

这也可以使用较新的 @Resource 注释来完成,但如果您已经切换到该注释,那么您也会知道如何在此处应用这一点.

This can also be done with the newer @Resource annotation, but if you've already switched to that then you'll know how to apply this point there too.

通过此更改,位于 java:comp/env/jdbc/BonusPayoutDS 位置的现有 JNDI 查找现在将使用非共享连接,并且 ResultSet 不会在每个块事务结束时关闭.

With this change, the existing JNDI lookup at location: java:comp/env/jdbc/BonusPayoutDS will now use unshared connections, and the ResultSet will not be closed at the end of each chunk transaction.

此行为被间接记录这里 在 WebSphere Application Server 传统文档中.(我在 Liberty 文档中没有看到它,在某些情况下,Liberty 中的行为基本相同,并且 Liberty 中没有单独记录该主题.)对于批处理用户来说有点间接.也很难完全描述,因为文档说确切的行为因 DB 和 JDBC 提供程序而异.但这应该适用于 DB2.

This behavior is indirectly documented here in the WebSphere Application Server traditional documentation. (I don't see it in the Liberty documentation, there are some cases like these where the behavior is basically identical in Liberty and the topic is not documented separately in Liberty.) It's a bit indirect for the batch user. Also it's hard to describe completely since as the doc says the exact behavior varies by DB and JDBC provider. But this should work for DB2.

更新: 在 Liberty 的较新版本(自 17.0.0.1 起)中,可以通过使用strong>enableSharingForDirectLookups 属性,例如:

UPDATE: In newer (since 17.0.0.1) version of Liberty the unshareable connection can be obtained without needing to use a resource reference by configuring the connectionManager using the enableSharingForDirectLookups attribute, e.g.:

<connectionManager ...  enableSharingForDirectLookups="false"/>

这篇关于在 (Liberty) Batch 块步骤中,获取“ResultSet is closed"从步骤前面发出的数据库查询中滚动 ResultSet 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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