You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: When sql statements in mybatis query SQL Server data using clickhouse's jdbc function, #{} cannot set parameter values #1440
jdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)legacyOnly the v1 stack (clickhouse-client, clickhouse-http-client, clickhouse-jdbc) has the problemqueriesArea: how the client builds and runs statements (parameters, quoting, batches)questionstalewontfix
When I use mybatis, I need to find sqlserver data through the clickhouse jdbc function, but I found that sqlserver statements cannot use #{} to set parameters, but sql outside the jdbc function can use #{} to set parameters
Specifically, when I use the following SQL statement:
<select id="selectDownloadLogList" resultType="com.test.DownloadLogDTO">
select * from jdbc ("commerce","select * from DownloadLog where id = #{query.id}")
</select>
Error log
Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='query.id', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property.
Cause: java.sql.SQLException: Can't set parameter at index 1 due to no JDBC style '?' placeholder found in the query
Caused by: java.sql.SQLException: Can't set parameter at index 1 due to no JDBC style '?' placeholder found in the query
at com.clickhouse.jdbc.SqlExceptionUtils.clientError(SqlExceptionUtils.java:73)
at com.clickhouse.jdbc.internal.AbstractPreparedStatement.toArrayIndex(AbstractPreparedStatement.java:26)
at com.clickhouse.jdbc.internal.SqlBasedPreparedStatement.setLong(SqlBasedPreparedStatement.java:319)
I found in com.clickhouse.jdbc.JdbcParameterizedQuery#parse method "ClickHouseUtils. IsQuote (ch)" will skip ['] and ["] in the middle of the content will not go to determine whether it will have[?] This makes it very difficult for me. Is there any good solution?
Hi @liuyudong-pacvue, it's expected that SQL parameter cannot be part of a string. Perhaps you can make the whole statement as a parameter?
Although it could be fun to play with jdbc table function, but please do NOT use it on production. This is because that it has issue in both design and implementation. Besides stability issue, the most severe one is probably ClickHouse/ClickHouse#36385.
Hi, If using the jdbc function is not recommended, is there a better way to perform joins and other related operations with other types of databases? If so, please let me know
Hi @SinceNovember, if you're talking about federated query on ClickHouse, perhaps url table function is more reliable, although it requires you to implement a web service to bridge the query to corresponding database. If it's just about small amount of data for convenience as shown above, you may consider to issue separate query for external data, put it into an external table like below on ClickHouse for joining.
This issue has been automatically marked as stale because it has not had activity in the last year. It will be closed in 30 days if no further activity occurs. Please feel free to leave a comment if you believe the issue is still relevant. Thank you for your contributions!
jdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)legacyOnly the v1 stack (clickhouse-client, clickhouse-http-client, clickhouse-jdbc) has the problemqueriesArea: how the client builds and runs statements (parameters, quoting, batches)questionstalewontfix
Activity
liuyudong-pacvue commentedon Sep 6, 2023
I found in com.clickhouse.jdbc.JdbcParameterizedQuery#parse method "ClickHouseUtils. IsQuote (ch)" will skip ['] and ["] in the middle of the content will not go to determine whether it will have[?] This makes it very difficult for me. Is there any good solution?
zhicwu commentedon Sep 6, 2023
Hi @liuyudong-pacvue, it's expected that SQL parameter cannot be part of a string. Perhaps you can make the whole statement as a parameter?
Although it could be fun to play with jdbc table function, but please do NOT use it on production. This is because that it has issue in both design and implementation. Besides stability issue, the most severe one is probably ClickHouse/ClickHouse#36385.
SinceNovember commentedon Sep 6, 2023
Hi, If using the jdbc function is not recommended, is there a better way to perform joins and other related operations with other types of databases? If so, please let me know
zhicwu commentedon Sep 7, 2023
Hi @SinceNovember, if you're talking about federated query on ClickHouse, perhaps
urltable function is more reliable, although it requires you to implement a web service to bridge the query to corresponding database. If it's just about small amount of data for convenience as shown above, you may consider to issue separate query for external data, put it into an external table like below on ClickHouse for joining.clickhouse-java/examples/jdbc/src/main/java/com/clickhouse/examples/jdbc/Advanced.java
Lines 63 to 83 in f2ea0e1
liuyudong-pacvue commentedon Sep 8, 2023
Thank you for your reply and I will refer to your comments!
github-actions commentedon Jan 8, 2025
This issue has been automatically marked as stale because it has not had activity in the last year. It will be closed in 30 days if no further activity occurs. Please feel free to leave a comment if you believe the issue is still relevant. Thank you for your contributions!