# The fetchSize setting is not being honored when using JDBC with a PreparedStatement

**URL:** <https://community.cratedb.com/t/the-fetchsize-setting-is-not-being-honored-when-using-jdbc-with-a-preparedstatement/2054>\
**Category:** SQL\
**Created:** [July 18, 2025, 11:00am UTC](https://community.cratedb.com/t/the-fetchsize-setting-is-not-being-honored-when-using-jdbc-with-a-preparedstatement/2054 "2025-07-18T11:00:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![atish11pune](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@atish11pune](https://community.cratedb.com/u/atish11pune)\
**Post date:** [July 18, 2025, 11:00am UTC](https://community.cratedb.com/t/the-fetchsize-setting-is-not-being-honored-when-using-jdbc-with-a-preparedstatement/2054/1 "2025-07-18T11:00:27Z")

</div>

We are using the CrateDB JDBC driver version **2.7.0** Below is the dependency

```auto
<dependency>
    <groupId>io.crate</groupId>
    <artifactId>crate-jdbc</artifactId>
    <version>2.7.0</version>
</dependency>

```

And attempting to use the `fetchSize` parameter as mentioned in the official documentation:  
[CrateDB PostgreSQL Interface – fetchSize](https://cratedb.com/docs/crate/reference/en/latest/interfaces/postgres.html#interface-postgresql)

Unfortunately, it is not working as expected.

We have also followed all the prerequisites mentioned in the following PostgreSQL JDBC documentation:  
[PostgreSQL JDBC – Using Cursors](https://jdbc.postgresql.org/documentation/query/#getting-results-based-on-a-cursor)

However, even when setting the `fetchSize` to **1000** , if the query returns **10,000** records, the entire result set is still fetched at once, instead of being fetched in batches as expected.

Any help or guidance on this would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![kneth](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/kneth/32/1308_2.png) [@kneth](https://community.cratedb.com/u/kneth)\
**Post date:** [July 21, 2025, 12:48pm UTC](https://community.cratedb.com/t/the-fetchsize-setting-is-not-being-honored-when-using-jdbc-with-a-preparedstatement/2054/2 "2025-07-21T12:48:13Z")

</div>

Did you disable auto commits? For example `connection.setAutoCommit(false);`

---

<div class="post-metadata">

**Author:** ![atish11pune](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@atish11pune](https://community.cratedb.com/u/atish11pune)\
**Post date:** [July 21, 2025, 12:56pm UTC](https://community.cratedb.com/t/the-fetchsize-setting-is-not-being-honored-when-using-jdbc-with-a-preparedstatement/2054/3 "2025-07-21T12:56:27Z")

</div>

Yes, I have already followed all of the points mentioned below:

- The connection to the server is using the V3 protocol (default for server versions 7.4 and later).
- The connection is **not** in autocommit mode, since cursors are closed at the end of transactions in autocommit mode.
- The `Statement` is created with a `ResultSet` type of `ResultSet.TYPE_FORWARD_ONLY` (which is the default), so no changes were needed in that regard. I understand this also means the `ResultSet` cannot be scrolled or randomly accessed.
- The query being executed is a single statement (not multiple statements separated by semicolons).

Despite meeting all these conditions, the `fetchSize` is still not being honored — the entire result set is returned at once instead of being fetched in smaller batches.

Any help or insights would be appreciated.

---

<div class="post-metadata">

**Author:** ![Baur](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/baur/32/284_2.png) [@Baur](https://community.cratedb.com/u/Baur)\
**Post date:** [July 25, 2025, 7:23am UTC](https://community.cratedb.com/t/the-fetchsize-setting-is-not-being-honored-when-using-jdbc-with-a-preparedstatement/2054/4 "2025-07-25T07:23:50Z")

</div>

Hi @atish11pune, I’m not sure I understand second point correctly. Do you mean you explicitly disabled autocommit (as adviced by @kneth) or you are implying that having cursors open == having autocommit disabled?

Explicitly disabling should work, see test methods in the [autocommit and fetch size by chaudum · Pull Request #204 · crate/crate-jdbc · GitHub](https://github.com/crate/crate-jdbc/pull/204/files)

We can’t imply autocommit setting from a “cursor state at the end of transaction” because CrateDB doesn’t support transactions, so there is no such thing as end of transaction in CrateDB.

See also [SQL compatibility - CrateDB: Reference](https://cratedb.com/docs/crate/reference/en/latest/appendices/compatibility.html#transactions-begin-start-commit-and-rollback)

---

<div class="post-metadata">

**Author:** ![atish11pune](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@atish11pune](https://community.cratedb.com/u/atish11pune)\
**Post date:** [August 7, 2025, 6:55am UTC](https://community.cratedb.com/t/the-fetchsize-setting-is-not-being-honored-when-using-jdbc-with-a-preparedstatement/2054/5 "2025-08-07T06:55:18Z")

</div>

Yes, we have set auto\_commit = false, and it still did not work.

---

<div class="post-metadata">

**Author:** ![Baur](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/baur/32/284_2.png) [@Baur](https://community.cratedb.com/u/Baur)\
**Post date:** [September 4, 2025, 7:45am UTC](https://community.cratedb.com/t/the-fetchsize-setting-is-not-being-honored-when-using-jdbc-with-a-preparedstatement/2054/6 "2025-09-04T07:45:11Z")

</div>

Please share a code snippet with a minimal reproduction
