ClickHouse / clickhouse-java

ClickHouse Java Clients & JDBC Driver
https://clickhouse.com
Apache License 2.0
1.43k stars 526 forks source link

IllegalArgumentException caused by local default datetime when using nullAsDefault property #1735

Open yanye666 opened 1 month ago

yanye666 commented 1 month ago

Still got this problem in version:0.3.2-patch11, When I set 0 or null timestamp to ClickHouse DataTime column,I got this err

DateTime(-28800) should between 0 and 4294967295000 inclusive of both values

Originally posted by @cod-soap in https://github.com/ClickHouse/clickhouse-java/issues/999#issuecomment-1445802811

yanye666 commented 1 month ago

When I set the object property string to "1970-01-01 00:00:00" ,throw exception,below the debug

image

When I set the object property string to "1970-01-01 08:00:00" ,avoid exception,database query show image

chernser commented 1 month ago

Good day, @yanye666 !

How do you set null timestamp?

Here is my code that works for latest version 0.6.2

 try (ClickHouseConnection conn = newConnection(props);
                PreparedStatement ps = conn.prepareStatement("select toDateTime(?)")) {

            ps.setTimestamp(1, null);
            ResultSet rs = ps.executeQuery();
            Assert.assertTrue(rs.next());
            Assert.assertNull(rs.getObject(1));
        }

Thanks!

yanye666 commented 1 month ago

Good day, @yanye666 !

How do you set null timestamp?

Here is my code that works for latest version 0.6.2


 try (ClickHouseConnection conn = newConnection(props);

                PreparedStatement ps = conn.prepareStatement("select toDateTime(?)")) {

            ps.setTimestamp(1, null);

            ResultSet rs = ps.executeQuery();

            Assert.assertTrue(rs.next());

            Assert.assertNull(rs.getObject(1));

        }

Thanks!

I'm not set null.I want to insert the default 1970 timestamp to avoid clickhouse nullable. But as shown in the figure, I have to set 1970-01-01 08:00:00, otherwise I will report an error.Inspection of the first diagram