JDBC operations

How do YOU get the resulting SQL in a PrepareStatement?

    public static ResultSet queryBySql(String sql, Object... params) throws SQLException {
        final PreparedStatement preparedStatement = connection.prepareStatement(sql);
        for (int i = 0; i < params.length; i++) {
            preparedStatement.setObject(i + 1, params[i]);
        }
        final ClickHousePreparedStatementImpl clickHousePreparedStatement = (ClickHousePreparedStatementImpl) preparedStatement;
        final String s = clickHousePreparedStatement.asSql();
        // There is an API
        log.info("clickhouse sql:{}", s);
        return preparedStatement.executeQuery();
    }
Copy the code