在(自由)批量块步骤中,获取“ResultSet被关闭”当在步骤中较早发出的数据库查询中滚动ResultSet时 [英] In a (Liberty) Batch chunk step, getting "ResultSet is closed" when scrolling through ResultSet from database query issued earlier in the step

查看:218
本文介绍了在(自由)批量块步骤中,获取“ResultSet被关闭”当在步骤中较早发出的数据库查询中滚动ResultSet时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



在块中,我将checkpoint策略设置为item和itemcount为5.



输出是要读取的前5个记录,



在这个来自IBM网站的java批处理代码,它们在查询中具有起始和结束参数。



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



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

解决方案

尝试配置数据源要使用不可靠的连接。



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

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

所以完全你会有:

 < web-app id =BonusPayoutversion =3.1xmlns =http://xmlns.jcp.org/xml/ns/javaeexmlns:xsi = http://www.w3.org/2001/XMLSchema-instancexsi: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>这是BonusPayout示例。< / description>
< resource-ref>
< description>奖金支付DS< / description>
< res-ref-name> jdbc / BonusPayoutDS< / res-ref-name>
< res-type> javax.sql.DataSource< / res-type>
< res-auth>容器< / res-auth>
< res-sharing-scope> Unshareable< / res-sharing-scope>
< / resource-ref>
< / web-app>

这也可以用较新的 @Resource 注释完成,但如果您已经切换到那里,那么您将知道如何应用这一点。



随着这一变化,现有的JNDI查找位置: java :comp / env / jdbc / BonusPayoutDS 现在将使用非共享连接,并且ResultSet将不会在每个块事务结束时关闭。



此行为间接记录了这里。 (我在Liberty文档中没有看到,在Liberty文档中有些情况类似于Liberty中的行为基本相同,而Liberty中没有单独记录该主题)。对于批处理用户来说,这是一个间接的。此外,很难完全描述,因为文档说明DB和JDBC提供程序的确切行为有所不同。但这应该适用于DB2。


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

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

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

The output is the first 5 records being read and written over and over again.

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?

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

解决方案

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>

So in full you'd have:

<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>

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.

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.

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.

这篇关于在(自由)批量块步骤中,获取“ResultSet被关闭”当在步骤中较早发出的数据库查询中滚动ResultSet时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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