Repository: clickhouse/clickhouse-java
Issue: Multiple values insert prepared statement

[QUESTION] about multiple values in prepared statement. 
Probably, after this [COMMIT](https://github.com/ClickHouse/clickhouse-jdbc/commit/09cd66e564966d76d72f996754dbf8311bf1b49d)
between **patch5** and **patch6** and later versions.

I can't anymore use multiple values in prepared statement, like
`PreparedStatement stmt = Connection#prepareStatement("insert into table values(?,?), (?,?)");`
only 
`PreparedStatement stmt = Connection#prepareStatement("insert into table values(?,?)");`
and then insert values for each row separated by 
`stmt.addBatch()`

Is it final change or, maybe some options are needed to be turned on? 

Under the hood detail.
`values (?,?), (?,?)` is not properly parsed and it doesn't see `ClickHouseSqlStatement.KEYWORD_VALUES_START` (values start position index in sql).
Here in the [CODE](https://github.com/ClickHouse/clickhouse-jdbc/blob/1d6257c51a1d5db0a4732441fc3c1c7dba7b5316/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java#L601) returns null which cause NPE later in code.
For `values (?,?)` all worked correctly. 

Changed files:
clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHousePreparedStatementTest.java
clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java

diff --git a/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java b/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java
index ebef724b..3df1afb6 100644
--- a/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java
+++ b/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java
@@ -615,14 +615,17 @@ public class ClickHouseConnectionImpl extends JdbcWrapper implements ClickHouseC
                     !parsedStmt.containsKeyword("SELECT") && parsedStmt.hasValues() &&
                     (!parsedStmt.hasFormat() || clientRequest.getFormat().name().equals(parsedStmt.getFormat()))) {
                 String query = parsedStmt.getSQL();
-                int startIndex = parsedStmt.getPositions().get(ClickHouseSqlStatement.KEYWORD_VALUES_START);
-                int endIndex = parsedStmt.getPositions().get(ClickHouseSqlStatement.KEYWORD_VALUES_END);
-                boolean useStream = true;
-                for (int i = startIndex + 1; i < endIndex; i++) {
-                    char ch = query.charAt(i);
-                    if (ch != '?' && ch != ',' && !Character.isWhitespace(ch)) {
-                        useStream = false;
-                        break;
+                boolean useStream = false;
+                Integer startIndex = parsedStmt.getPositions().get(ClickHouseSqlStatement.KEYWORD_VALUES_START);
+                if (startIndex != null) {
+                    useStream = true;
+                    int endIndex = parsedStmt.getPositions().get(ClickHouseSqlStatement.KEYWORD_VALUES_END);
+                    for (int i = startIndex + 1; i < endIndex; i++) {
+                        char ch = query.charAt(i);
+                        if (ch != '?' && ch != ',' && !Character.isWhitespace(ch)) {
+                            useStream = false;
+                            break;
+                        }
                     }
                 }
 
diff --git a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHousePreparedStatementTest.java b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHousePreparedStatementTest.java
index 025b67ad..2f496ff9 100644
--- a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHousePreparedStatementTest.java
+++ b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHousePreparedStatementTest.java
@@ -1,8 +1,10 @@
 package com.clickhouse.jdbc;
 
 import java.io.ByteArrayInputStream;
+import java.math.BigDecimal;
 import java.net.Inet4Address;
 import java.net.Inet6Address;
+import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.sql.BatchUpdateException;
 import java.sql.Connection;
@@ -1257,4 +1259,46 @@ public class ClickHousePreparedStatementTest extends JdbcIntegrationTest {
             Assert.assertFalse(rs.next());
         }
     }
+
+    @Test(groups = "integration")
+    public void testInsertWithMultipleValues() throws Exception {
+        try (ClickHouseConnection conn = newConnection(new Properties());
+                Statement s = conn.createStatement()) {
+            s.execute("drop table if exists test_insert_with_multiple_values; "
+                    + "CREATE TABLE test_insert_with_multiple_values(a Int32, b Nullable(String)) ENGINE=Memory");
+            try (PreparedStatement ps = conn.prepareStatement(
+                    "INSERT INTO test_insert_with_multiple_values values(?, ?), (2 , ? ), ( ? , '') , (?,?) ,( ? ,? )")) {
+                ps.setInt(1, 1);
+                ps.setNull(2, Types.VARCHAR);
+                ps.setObject(3, "er");
+                ps.setInt(4, 3);
+                ps.setInt(5, 4);
+                ps.setURL(6, new URL("http://some.host"));
+                ps.setInt(7, 5);
+                ps.setString(8, null);
+                ps.executeUpdate();
+            }
+
+            try (ResultSet rs = s.executeQuery("select * from test_insert_with_multiple_values order by a")) {
+                Assert.assertTrue(rs.next());
+                Assert.assertEquals(rs.getByte(1), (byte) 1);
+                Assert.assertEquals(rs.getObject(2), null);
+                Assert.assertTrue(rs.wasNull());
+                Assert.assertTrue(rs.next());
+                Assert.assertEquals(rs.getBigDecimal(1), BigDecimal.valueOf(2L));
+                Assert.assertEquals(rs.getString(2), "er");
+                Assert.assertTrue(rs.next());
+                Assert.assertEquals(rs.getString(1), "3");
+                Assert.assertEquals(rs.getObject(2), "");
+                Assert.assertTrue(rs.next());
+                Assert.assertEquals(rs.getShort(1), (short) 4);
+                Assert.assertEquals(rs.getURL(2), new URL("http://some.host"));
+                Assert.assertTrue(rs.next());
+                Assert.assertEquals(rs.getObject(1), Integer.valueOf(5));
+                Assert.assertEquals(rs.getString(2), null);
+                Assert.assertTrue(rs.wasNull());
+                Assert.assertFalse(rs.next());
+            }
+        }
+    }
 }