基于sharding-jdbc的使用限制
使用限制
JDBC未支持列表
- Sharding-JDBC暫時未支持不常用的JDBC方法。
DataSource接口
- 不支持timeout相關(guān)操作
Connection接口
- 不支持存儲過程,函數(shù),游標的操作
- 不支持執(zhí)行native的SQL
- 不支持savepoint相關(guān)操作
- 不支持Schema/Catalog的操作
- 不支持自定義類型映射
Statement和PreparedStatement接口
- 不支持返回多結(jié)果集的語句(即存儲過程,非SELECT多條數(shù)據(jù))
- 不支持國際化字符的操作
對于ResultSet接口
- 不支持對于結(jié)果集指針位置判斷
- 不支持通過非next方法改變結(jié)果指針位置
- 不支持修改結(jié)果集內(nèi)容
- 不支持獲取國際化字符
- 不支持獲取Array
JDBC 4.1
- 不支持JDBC 4.1接口新功能
- 查詢所有未支持方法,請閱讀com.dangdang.ddframe.rdb.sharding.jdbc.unsupported包。
SQL語句限制
- 不支持DDL語句
- 不支持子語句
- 不支持UNION 和 UNION ALL
- 不支持特殊INSERT
- 每條INSERT語句只能插入一條數(shù)據(jù),不支持VALUES后有多行數(shù)據(jù)的語句
- 不支持DISTINCT聚合
shardingjdbc使用及踩坑內(nèi)容
1.使用shardingjdbc做分庫分表
最近公司由于業(yè)務(wù)需要,對日益增加的數(shù)據(jù)量越來越無法容忍,遂作出分庫分表的決定,考察了幾個技術(shù)方案后,決定使用shardingsphere做分表中間件。
使用maven拉取jar包:
<dependency> <groupId>io.shardingsphere</groupId> <artifactId>sharding-jdbc</artifactId> <version>3.0.0.M3</version> </dependency> <dependency> <groupId>io.shardingsphere</groupId> <artifactId>sharding-jdbc-spring-namespace</artifactId> <version>3.0.0.M3</version> </dependency>
分表配置:
<?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:sharding="http://shardingsphere.io/schema/shardingsphere/sharding" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://shardingsphere.io/schema/shardingsphere/sharding http://shardingsphere.io/schema/shardingsphere/sharding/sharding.xsd" default-autowire="byName"> <!-- 分表算法 --> <bean id="tableShardingAlgorithm" class="pxf.commom.support.sharding.tableShardingAlgorithm" /> <sharding:complex-strategy id="tableStrategy" sharding-columns="uid" algorithm-ref="tableShardingAlgorithm" /> <!-- ds_0為數(shù)據(jù)源,如果做分庫,可配置多個數(shù)據(jù)源;不分表的表不用在此做配置--> <sharding:data-source id="dataSource"> <sharding:sharding-rule data-source-names="ds_0" default-data-source-name="ds_0" > <sharding:table-rules> <sharding:table-rule logic-table="test_table" actual-data-nodes="ds_0.test_table_$->{0..128}" table-strategy-ref="tableStrategy" /> </sharding:table-rules> </sharding:sharding-rule> </sharding:data-source> </beans>
2.踩坑內(nèi)容
1). 用于分表的列在sql中不能為空,所以像insert之類的語句需要做下非空判斷;
2). sqlmap中LONGVARCHER字段不能使用,會報序列化異常,可改為VARCHAR類型;
3). union語法不支持,可改為OR查詢(shardingjdbc連OR也不支持,所以建議使用shardingsphere)。
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
springcloud-gateway整合jwt+jcasbin實現(xiàn)權(quán)限控制的詳細過程
這篇文章主要介紹了springcloud-gateway整合jwt+jcasbin實現(xiàn)權(quán)限控制,基于springboot+springcloud+nacos的簡單分布式項目,項目交互采用openFeign框架,單獨提取出來成為一個獨立的model,需要的朋友可以參考下2023-02-02java底層AQS實現(xiàn)類ReentrantLock鎖的構(gòu)成及源碼解析
本章我們就要來學習一下第一個?AQS?的實現(xiàn)類:ReentrantLock,看看其底層是如何組合?AQS?,實現(xiàn)了自己的那些功能,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步2022-03-03Springboot AOP對指定敏感字段數(shù)據(jù)加密存儲的實現(xiàn)
本篇文章主要介紹了利用Springboot+AOP對指定的敏感數(shù)據(jù)進行加密存儲以及對數(shù)據(jù)中加密的數(shù)據(jù)的解密的方法,代碼詳細,具有一定的價值,感興趣的小伙伴可以了解一下2021-11-11Apache?SkyWalking?監(jiān)控?MySQL?Server?實戰(zhàn)解析
這篇文章主要介紹了Apache?SkyWalking?監(jiān)控?MySQL?Server?實戰(zhàn)解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-09-09springboot使用Thymeleaf報錯常見的幾種解決方案
這篇文章主要介紹了springboot使用Thymeleaf報錯常見的幾種解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-11-11