Skip to content

Clickhouse jdbc-v2: Prepared Statement not working when column names like "ip" or "url" appear in query #2617

@adityam31

Description

@adityam31

Description

If the query contains column names like "ip" or "url" then PreparedStatement 's setObject() or any set methods throw java.lang.ArrayIndexOutOfBoundException

Steps to reproduce

  1. Create a simple table in clickhouse CREATE TABLE myusers ( id UInt64, ip String, url String, tenant String) ENGINE = MergeTree() PRIMARY KEY (id);
  2. Write a simple query "select ip from myusers where tenant=?" in java code
  3. Use connection.prepareStatement(query) to generate PreparedStatement object
  4. Call setObject(1,1) on prepare statement object
Image Image

same observed for url

Image

Error Log or Exception StackTrace

java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at com.clickhouse.jdbc.PreparedStatementImpl.setObject(PreparedStatementImpl.java:291)

Expected Behaviour

It should allow setting objects in PreparedStatement without exception

Code Example

String query = "select ip from myusers where tenant=?";
PreparedStatement ps = connection.prepareStatement(query);
ps.setObject(1, 1);

Configuration

Client Configuration

<dependency>
    <groupId>com.clickhouse</groupId>
    <artifactId>clickhouse-jdbc</artifactId>
    <version>0.9.2</version>
    <classifier>all</classifier>
</dependency>

and also observed same for 0.9.1 version

<dependency>
    <groupId>com.clickhouse</groupId>
    <artifactId>clickhouse-jdbc</artifactId>
    <version>0.9.1</version>
    <classifier>all</classifier>
</dependency>

Environment

  • Cloud
  • Client version: java jdbc v2 0.9.2 and 0.9.1
  • Language version: Java 17
  • OS:

ClickHouse Server

  • ClickHouse Server version: 25.3.6.56-lts
  • ClickHouse Server non-default settings, if any:
  • CREATE TABLE statements for tables involved:
  • Sample data for all these tables, use clickhouse-obfuscator if necessary

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions