Skip to content

JDBC Insert query failing if the query does not contain VALUES #2283

@tomsajuk

Description

@tomsajuk

Describe the bug

Using jdbc v8

If the INSERT statement does not contain VALUES keyword during the PreparedStatement query creation, the insert fails due to syntax error.

Issue seems to be due to the the constructor doing a substring.

valueSegments = originalSql.substring(originalSql.indexOf("VALUES") + 6).split("\\?");

Any possibility that this will be changed as I would like to use other insert statements like insert into select from or using format json

Steps to reproduce

  1. Create a preparedStatement that does not contain VALUES
  2. Add paremeters required
  3. Execute PS

Expected behaviour

Inserts without error

Code example

String query = "INSERT INTO persons FORMAT JSON { 'name': 'Example' }";
final PreparedStatement preparedStatement = con.prepareStatement(query);
preparedStatement.execute()

Error log

Image

Configuration

Environment

  • Client version: clickhouse-jdbc 0.8.2.
  • Language version: Java 21
  • OS: macOS

ClickHouse server

  • ClickHouse Server version: 25.1.1.4165
  • 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

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions