一、概述
shardingsphere-jdbc 作为知名开源数据库中间件,主要功能有读写分离、分库分表。功能很强大,但也存在一定兼容性,部分 SQL 无法正常解析。
文档:
存在的问题
- 报错:
attempting to get column 'XXX' from result set. Cause: java.sql.SQLException: Column Index out of range, 29 > 28
原因:连表查询时,存在查询列使用通配符 *
,例如:SELECT a.* , b.c1, b.c2 FROM tableA a , tableB b WHERE ...
解决方案:
a. 将 SELECT 查询列中的 a.* 放到最后,例如:SELECT b.c1, b.c2, a.* FROM tableA a , tableB b WHERE ...
b. 降级使用 sharding-jdbc 4.1.1
- 报错:
Can not get index from column label
原因:SQL 语句中函数列缺少别名,例如:SELECT IFNULL((SELECT COUNT(*) FROM tableA a WHERE ...),0)
解决方案:
a. 添加查询函数列的别名,例如:SELECT IFNULL((SELECT COUNT(*) FROM tableA a WHERE ...),0) AS countNum
b. 降级使用 sharding-jdbc 4.1.1