clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

external data jdbc does not work

Open den-crane opened this issue 2 years ago • 1 comments

    public static void main(String[] args) throws SQLException {
         final String DB_URL = "jdbc:clickhouse://github.demo.trial.altinity.cloud:8443?&ssl=true";
         final String USER = "demo";
         final String PASS = "demo";
         final String QUERY = "SELECT count() FROM (select 3 x) WHERE x IN { tt 'table1' }";

        ClickHouseExternalTable build = ClickHouseExternalTable.builder().name("table1").columns("id Int8")
                .format(ClickHouseFormat.TSV)
                .content(new ByteArrayInputStream("1".getBytes(StandardCharsets.US_ASCII)))
                .build();

        Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
        PreparedStatement stmt = conn.prepareStatement(QUERY);
        stmt.setObject(1, build);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            System.out.println(rs.getString(1));
        }
    }


WARNING: don't know how to handle parameter pair: 
Exception in thread "main" java.sql.SQLException: Can't set parameter at index 1 due to no JDBC style '?' placeholder found in the query

den-crane avatar Apr 04 '22 12:04 den-crane

I know how this sounds like but you need to remove the space between { and tt :)

I'll enhance the parser together with query parameter support, after moving it to clickhouse-jdbc-ext.

zhicwu avatar Apr 04 '22 13:04 zhicwu