<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Marc Sturlese &#187; MySQL</title>
	<atom:link href="http://www.marcsturlese.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marcsturlese.com</link>
	<description>Life, code and stuff</description>
	<lastBuildDate>Sun, 27 Jun 2010 14:45:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>MySQL streaming setting fetchSize to Integer.MIN_VALUE</title>
		<link>http://www.marcsturlese.com/2009/01/17/mysql-streaming-setting-fetchsize-to-integermin_value/</link>
		<comments>http://www.marcsturlese.com/2009/01/17/mysql-streaming-setting-fetchsize-to-integermin_value/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 19:53:04 +0000</pubDate>
		<dc:creator>Marc Sturlese</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.marcsturlese.com/?p=18</guid>
		<description><![CDATA[Have you ever experienced a java.lang.OutOfMemoryError: Java heap space due to too big selects? We can avoid that thanks to the fetchSize parameter initialized at statement creation time. FetchSize decides how many rows of the select MySQL must store in the buffer before dealing with the data. Setting that parameter to it&#8217;s minimum value we [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever experienced a <strong>java.lang.OutOfMemoryError: Java heap space</strong><br />
due to too big selects?<br />
We can avoid that thanks to the <strong>fetchSize</strong> parameter initialized at <strong>statement</strong> creation time. <strong>FetchSize</strong> decides how many rows of the select <strong>MySQL</strong> must store in the buffer before dealing with the data. Setting that parameter to it&#8217;s minimum value we will be able to do streaming with all rows.<br />
The minimum value is still pretty odd for me as I thought it would be 1 (thinking 1 was the minum numer of rows to be stored in the buffer) but it is -2^31, the minimum value java can store in an Integer!</p>
<p>Another solution would be to paginate the select setting a limit value. The problem with this is that the more selects we do, the slower <strong>MySQL</strong> will deal with rows. Doing streamaing with the <strong>fetchSize</strong> parameter we just need one select and the &#8220;rows deal with speed&#8221; does not decrease. <strong>MySQL</strong> will deal with the rows buffering by itself.</p>
<p>The <strong>statement</strong> creation should look like this:<br />
<strong><br />
try {<br />
Connection c = getConnection();<br />
stmt = c.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);<br />
stmt.setFetchSize(Integer.MIN_VALUE);<br />
&#8230;<br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcsturlese.com/2009/01/17/mysql-streaming-setting-fetchsize-to-integermin_value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
