clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

Prepared statement with a parameter throws ArrayIndexOutOfBoundsException

Open rileythomp opened this issue 6 months ago • 0 comments

Description

Steps to reproduce

  1. Set up a clickhouse container, I'm running clickhouse/clickhouse-server:25.2-alpine. There's a database test_data, and it has a table categories. See bottom section for the create table statement.

  2. I'm using clojure, so I start a repl with clj -Sdeps '{:deps {com.clickhouse/clickhouse-jdbc {:mvn/version "0.9.0"}}}'

  3. Try to execute a prepared statement with a string parameter

(let [conn (java.sql.DriverManager/getConnection "jdbc:clickhouse://localhost:8123" "default" "")
      stmt (.prepareStatement conn "select * from test_data.categories WHERE test_data.categories.name = ? limit 4")]
    (.setString stmt 1 "African")
    (let [rs (.executeQuery stmt)]
      (while (.next rs)
        (println (.getString rs 1) (.getString rs 2)))))
  1. This returns
line 1:62 no viable alternative at input 'select*fromtest_data.categoriesWHEREtest_data.categories.name'
Execution error (ArrayIndexOutOfBoundsException) at com.clickhouse.jdbc.PreparedStatementImpl/setString (PreparedStatementImpl.java:197).
Index 0 out of bounds for length 0
  1. When starting the repl with 0.8.4 clj -Sdeps '{:deps {com.clickhouse/clickhouse-jdbc {:mvn/version "0.8.4"}}}' and running the same code I get the expected results of 1 African

Error Log or Exception StackTrace

line 1:62 no viable alternative at input 'select*fromtest_data.categoriesWHEREtest_data.categories.name'
Execution error (ArrayIndexOutOfBoundsException) at com.clickhouse.jdbc.PreparedStatementImpl/setString (PreparedStatementImpl.java:197).
Index 0 out of bounds for length 0

Expected Behaviour

It returns the expected results, e.g.

1 African

Code Example

(let [conn (java.sql.DriverManager/getConnection "jdbc:clickhouse://localhost:8123" "default" "")
        stmt (.prepareStatement conn "select * from test_data.categories WHERE test_data.categories.name = ? limit 4")]
    (.setString stmt 1 "African")
    (let [rs (.executeQuery stmt)]
      (while (.next rs)
        (println (.getString rs 1) (.getString rs 2)))))

Configuration

Client Configuration


Environment

  • [ ] Cloud
  • Client version: 0.9.0
  • Language version: Clojure CLI version 1.12.0.1488
  • OS: Sequoia 15.3.1

ClickHouse Server

  • ClickHouse Server version: 25.2.2.39
  • ClickHouse Server non-default settings, if any:
  • CREATE TABLE statements for tables involved:
CREATE TABLE test_data.categories
(
    `id` Int32,
    `name` Nullable(String)
)
ENGINE = MergeTree
ORDER BY id
SETTINGS allow_nullable_key = 1, index_granularity = 8192

rileythomp avatar Jun 18 '25 22:06 rileythomp