本文介绍了Ibatis queryWithRowHandler()似乎仍能获取所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ibatis 2.3.4和Mysql 5.1.37,将mysql-java-connector 5.1.6和Java 1.6一起使用

I'm using Ibatis 2.3.4 and Mysql 5.1.37, with mysql-java-connector 5.1.6 with java 1.6

我有从单个表返回很多行的查询.为此,本手册建议使用queryWithRowHandler().但是,当我调用此查询时,它似乎仍在内部获取所有行(在完成第一次handleRow()调用之前,内存的存储速度非常快.

I have query that returns very many rows from a single table. In order to do this the manual suggests to use queryWithRowHandler(). However when I call this query it internally still seems to fetch all rows (memory goes up very fast before the first handleRow() call is done.

我如何告诉Ibatis在时间部分取小的数据(我当然可以使用几个查询返回较小结果的列表,但是我认为这正是ibatis应该为我做的事情)?

How can I tell Ibatis to fetch small at the time portions (I can of course use several queries returning lists of smaller results, but in my opinion this is precisely what ibatis should do for me)?

我尝试将fetchSize设置为100,这似乎没有任何作用,与resultSetType="FORWARD_ONLY"相同. lazyLoadingEnabled未在任何地方设置,因此应启用.

I've tried setting a fetchSize of 100 for the statement, this doesn't seem to do anything, same for resultSetType="FORWARD_ONLY". lazyLoadingEnabled isn't set anywhere, so should be enable.

推荐答案

进行了更彻底的搜索后,我发现有关jbdc实现的mysql手册 mysql问题数据库具有一些有用的信息.归结为需要以下条件:

After doing more thorough search, I found that the mysql manual on the jbdc implementation and the mysql issue database had some useful information. This boils down to needing the following:

JDBC驱动程序需要使用游标的设置(这也可能有一些缺点)

The JDBC driver needs a setting to use cursor (this might have some downsides too)

  <transactionManager type="JDBC" commitRequired="false">
    <dataSource type="SIMPLE">
       ...
      <property name="Driver.useCursorFetch" value="true"/>
    </dataSource>
  </transactionManager>

该语句需要以下属性(具有任何有用的值fetchSize).

The statement needs the following properties (with any useful value fetchSize).

fetchSize="1000" resultSetType="FORWARD_ONLY"

这篇关于Ibatis queryWithRowHandler()似乎仍能获取所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 09:52