Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inner join + sharding-jdbc throw java.sql.SQLException: Column index out of range #879

Open
wangtiewu opened this issue Mar 19, 2023 · 0 comments

Comments

@wangtiewu
Copy link

wangtiewu commented Mar 19, 2023

JDK1.8
Springboot-2.1.3
mapper-spring-boot-starter-2.1.5
pagehelper-spring-boot-starter-1.2.10
shardingsphere-jdbc-core-5.3.1

sql语法如下,batch_id是主键,T_BATCH 一共37列,实际执行的时候发现去取第38列的值,列名是 a_b.batch_id,导致异常:
SELECT a.* FROM T_BATCH a INNER JOIN (SELECT batch_id FROM T_BATCH ORDER BY UPDATED_TIME DESC LIMIT ?) AS a_b ON a.batch_id = a_b.batch_id

SQL: SELECT a.* FROM T_BATCH a INNER JOIN (SELECT batch_id FROM T_BATCH ORDER BY UPDATED_TIME DESC LIMIT ?) AS a_b ON a.batch_id = a_b.batch_id

Cause: java.sql.SQLException: Column index out of range.

; Column index out of range.; nested exception is java.sql.SQLException: Column index out of range.] with root cause
java.sql.SQLException: Column index out of range.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.ResultSetMetaData.getField(ResultSetMetaData.java:405)
at com.mysql.jdbc.ResultSetMetaData.getColumnLabel(ResultSetMetaData.java:237)
at org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSetMetaData.getColumnLabel(ShardingSphereResultSetMetaData.java:106)
at org.apache.ibatis.executor.resultset.ResultSetWrapper.(ResultSetWrapper.java:59)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getFirstResultSet(DefaultResultSetHandler.java:243)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:180)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
at sun.reflect.GeneratedMethodAccessor170.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)
at com.sun.proxy.$Proxy395.query(Unknown Source)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
at sun.reflect.GeneratedMethodAccessor167.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
at com.clousev.zs.core.service.dao.pagination.PaginationInterceptor.intercept(PaginationInterceptor.java:65)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
at com.sun.proxy.$Proxy394.query(Unknown Source)
at com.github.pagehelper.util.ExecutorUtil.pageQuery(ExecutorUtil.java:177)
at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:104)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
at com.sun.proxy.$Proxy394.query(Unknown Source)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)

如果用raw JDBC + sharding-jdbc 执行上面的语法,结果正常。
帮忙看看,会是哪里的问题?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant