---
title: MySQL 8.x 驱动报错 ArrayIndexOutOfBoundsException-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于 MySQL 8.x 驱动报错 ArrayIndexOutOfBoundsException相关的常见问题和使用技巧，帮助您快速解决 MySQL 8.x 驱动报错 ArrayIndexOutOfBoundsException的难题。
---
切换语言

- 简体中文
- English

划线反馈

# MySQL 8.x 驱动报错 ArrayIndexOutOfBoundsException

更新时间：2023-11-13 02:05

内容类型：Troubleshoot  

本文介绍 MySQL 8.x 驱动报错 `ArrayIndexOutOfBoundsException`。

## 适用版本

OceanBase 数据库 V2.2.x、V3.1.x、V3.2.x。

## 问题现象

使用 MySQL JDBC 8.0.26+ 驱动报错如下。

```
java.lang.SQLException: 0] with root cause
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
  at com.mysql.cj.protocol.a.NativePacketPayload.readInteger(NativePacketPayload.java:398)
  at com.mysql.cj.protocol.a.NativePacketPayload.readString(NativePacketPayload.java:605)
  at com.mysql.cj.protocol.a.NativeServerSessionStateController$NativeServerSessionStateChanges.init(NativeServerSessionStateController.java:112)
  at com.mysql.cj.protocol.a.result.OkPacket.parse(OkPacket.java:66)
  at com.mysql.cj.protocol.a.NativeProtocol.readServerStatusForResultSets(NativeProtocol.java:1755)

```

## 问题原因

根据 MySQL 文档，对于 MySQL JDBC 8.0.26+ 驱动，需要增加 JDBC url 参数 `trackSessionState=true`。

```
For Connection/J 8.0.26 and later:
Connector/J can receive information on client session state changes tracked by the server if the tracking has been enabled on the server.

The reception of the information is enabled by
setting the Connector/J connection property trackSessionState to true
(default value is false for the property).

```

## 解决方法

方法一 (推荐): 使用 MySQL JDBC 8.0.25 版本的驱动。

方法二: 对于 MySQL JDBC 8.0.26+ 驱动，需要增加 JDBC url 参数 trackSessionState=true。

Previous

[OBClient 报错 error while load libncurses.so.5](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000429364)

Next

[租户白名单和 OceanBase JDBC 驱动的配置关系](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000217903) ![有帮助](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) 咨询热线
