---
title: Oracle 模式应用报错 invalid fetch size-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于Oracle 模式应用报错 invalid fetch size相关的常见问题和使用技巧，帮助您快速解决Oracle 模式应用报错 invalid fetch size的难题。
---
切换语言

- 简体中文
- English

划线反馈

# Oracle 模式应用报错 invalid fetch size

更新时间：2026-07-24 10:01

适用版本： V2.2.x、V2.4.x 内容类型：Troubleshoot  

## 适用版本

OceanBase 数据库所有版本。

## 问题现象

Oracle 模式下，应用使用 setFetchSize(Integer.MIN_VALUE) 报错 `invalid fetch size`。具体报错信息为：

```
SQLException: (conn=26835) invalid fetch size
SQLState: 42000
VendorError: -1
java.sql.SQLSyntaxErrorException: (conn=26835) invalid fetch size
    at com.oceanbase.jdbc.internal.util.exceptions.ExceptionFactory.createException(ExceptionFactory.java:108)
    at com.oceanbase.jdbc.internal.util.exceptions.ExceptionFactory.create(ExceptionFactory.java:209)
    at com.oceanbase.jdbc.OceanBaseStatement.setFetchSize(OceanBaseStatement.java:1390)
    at basicJDBCTest.TestProfileSQL.testQuery(TestProfileSQL.java:127)
    at basicJDBCTest.TestProfileSQL.main(TestProfileSQL.java:102)

```

代码样例：

```
PreparedStatement st1 = null;
String querySql1 = null;
querySql1 = String.format("select c1, c2, c3 from test_cursor where c1 > ? and c1 < ? order by c1");
st1 = conn.prepareStatement(querySql1, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
st1.setFetchSize(Integer.MIN_VALUE);

```

## 问题原因

MySQL 模式支持使用 Integer.MIN_VALUE 来设置 setFetchSize，Oracle 模式为了兼容 Oracle 数据库的用法，setFetchSize() 里只能指定 >0 的值。

## 解决办法

在 setFetchSize() 里指定 >0 的值，同时在连接串中指定 useCursorFetch=true。

```
conn = DriverManager.getConnection("jdbc:oceanbase://localhost/?useCursorFetch=true", "user", "s3cr3t");
stmt = conn.createStatement();
stmt.setFetchSize(100);

```

Previous

[JBoss 部署的 JDBC 应用出现连接数不足的问题](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000217899)

Next

[OB-JDBC 富客户端模式的详细配置步骤和使用方法](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000664390) ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
