MyCATApache/Mycat-Server · error · UnsupportedOperationException

batch not supported

Error message

batch not supported

What it means

MongoStatement.addBatch(String) explicitly throws UnsupportedOperationException with the message 'batch not supported'. The MongoDB backend of Mycat does not implement JDBC batch execution, so any attempt to queue a statement into a batch fails immediately.

Solutions

  1. Refactor the caller to execute each SQL statement individually with executeUpdate()/execute() in a loop instead of batching.
  2. Wrap batch-queuing logic in a capability check so the MongoDB backend uses per-statement execution.
  3. Remove addBatch usage from ORM/tooling configuration for this driver (e.g. disable JDBC batching in Hibernate: hibernate.jdbc.batch_size=0).
  4. Patch MongoStatement to implement batching by accumulating SQL and issuing multi-document writes to MongoDB.
  5. Use a different backend/driver if true server-side batching is required.

Example fix

// before
stmt.addBatch("INSERT INTO t VALUES (1)");
stmt.addBatch("INSERT INTO t VALUES (2)");
stmt.executeBatch();
// after
stmt.executeUpdate("INSERT INTO t VALUES (1)");
stmt.executeUpdate("INSERT INTO t VALUES (2)");
Defensive patterns

Strategy: try-catch

Validate before calling

// check backend before batching
DatabaseMetaData md = conn.getMetaData();
boolean batchSupported;
try { md.supportsBatchUpdates(); batchSupported = true; }
catch (SQLException e) { batchSupported = false; }
if (!batchSupported) { executeIndividually(conn, sqlList); return; }

Type guard

boolean isMongoBackend(Connection c) {
    try { return c.getMetaData().getDatabaseProductName().toLowerCase().contains("mongo"); }
    catch (SQLException e) { return false; }
}

Try / catch

try {
    stmt.addBatch(sql);
} catch (UnsupportedOperationException e) {
    stmt.executeUpdate(sql); // fall back to single-statement execution
}

Prevention

When it happens

Trigger: Calling addBatch(String sql) on a statement obtained from the MongoDB backend driver; using code paths that buffer SQL statements before executeBatch().

Common situations: Bulk-insert code written for MySQL/PostgreSQL reused against the MongoDB driver; ORMs or ETL tools that call addBatch automatically during bulk operations.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/22e514a86e1e628a. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/backend/jdbc/mongodb/MongoStatement.java:216

		return this._fetchSize;
	}

	@Override
	public int getResultSetConcurrency() throws SQLException {
		// 对象生成的 ResultSet 对象的结果集合并发性
		return 0;
	}

	@Override
	public int getResultSetType() throws SQLException {
		// 对象生成的 ResultSet 对象的结果集合类型。
		return 0;
	}

	@Override
	public void addBatch(String sql) throws SQLException {
		// 新增批处理
	   throw new UnsupportedOperationException("batch not supported");
	}

	@Override
	public void clearBatch() throws SQLException {
		throw new UnsupportedOperationException();
	}

	@Override
	public int[] executeBatch() throws SQLException {
		// 将一批命令提交给数据库来执行,如果全部命令执行成功,则返回更新计数组成的数组。
		throw new UnsupportedOperationException();
	}

	@Override
	public Connection getConnection() throws SQLException {
		
		return this._conn;
	}

View on GitHub (pinned to 65f8d8beb7)