diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java index c1482c6bf..dceb73b81 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java @@ -43,13 +43,7 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; import java.time.temporal.ChronoField; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; public class PreparedStatementImpl extends StatementImpl implements PreparedStatement, JdbcV2Wrapper { private static final Logger LOG = LoggerFactory.getLogger(PreparedStatementImpl.class); @@ -659,6 +653,8 @@ private static String encodeObject(Object x) throws SQLException { } tupleString.append(")"); return tupleString.toString(); + } else if (x instanceof UUID) { + return "'" + escapeString(((UUID) x).toString()) + "'"; } return escapeString(x.toString());//Escape single quotes diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java index 07d55bb4f..98929f834 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java @@ -16,6 +16,7 @@ import java.util.Arrays; import java.util.GregorianCalendar; import java.util.TimeZone; +import java.util.UUID; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -580,4 +581,27 @@ void testClearParameters() throws Exception { ps.execute(); } } + + @Test(groups = {"integration"}) + void testWriteCollection() throws Exception { + String sql = "insert into `test_issue_2327` (`id`, `uuid`) values (?, ?)"; + try (Connection conn = getJdbcConnection(); + PreparedStatementImpl ps = (PreparedStatementImpl) conn.prepareStatement(sql)) { + + try (Statement stmt = conn.createStatement()) { + stmt.execute("CREATE TABLE IF NOT EXISTS `test_issue_2327` (`id` Nullable(String), `uuid` UUID) ENGINE Memory;"); + } + UUID uuid = UUID.randomUUID(); + ps.setString(1, "testId01"); + ps.setObject(2, uuid); + ps.execute(); + + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("SELECT count(*) FROM `test_issue_2327`"); + Assert.assertTrue(rs.next()); + Assert.assertEquals(rs.getInt(1), 1); + } + } + + } }