clickhouse-java
clickhouse-java copied to clipboard
Prepared statement with a parameter throws ArrayIndexOutOfBoundsException
Description
Steps to reproduce
-
Set up a clickhouse container, I'm running
clickhouse/clickhouse-server:25.2-alpine. There's a databasetest_data, and it has a tablecategories. See bottom section for the create table statement. -
I'm using clojure, so I start a repl with
clj -Sdeps '{:deps {com.clickhouse/clickhouse-jdbc {:mvn/version "0.9.0"}}}' -
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)))))
- 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
- 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 of1 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 TABLEstatements 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
- Sample data for all these tables, use clickhouse-obfuscator if necessary