基于sharding-jdbc的使用限制
使用限制
JDBC未支持列表
- Sharding-JDBC暫時(shí)未支持不常用的JDBC方法。
DataSource接口
- 不支持timeout相關(guān)操作
Connection接口
- 不支持存儲(chǔ)過(guò)程,函數(shù),游標(biāo)的操作
- 不支持執(zhí)行native的SQL
- 不支持savepoint相關(guān)操作
- 不支持Schema/Catalog的操作
- 不支持自定義類型映射
Statement和PreparedStatement接口
- 不支持返回多結(jié)果集的語(yǔ)句(即存儲(chǔ)過(guò)程,非SELECT多條數(shù)據(jù))
- 不支持國(guó)際化字符的操作
對(duì)于ResultSet接口
- 不支持對(duì)于結(jié)果集指針位置判斷
- 不支持通過(guò)非next方法改變結(jié)果指針位置
- 不支持修改結(jié)果集內(nèi)容
- 不支持獲取國(guó)際化字符
- 不支持獲取Array
JDBC 4.1
- 不支持JDBC 4.1接口新功能
- 查詢所有未支持方法,請(qǐng)閱讀com.dangdang.ddframe.rdb.sharding.jdbc.unsupported包。
SQL語(yǔ)句限制
- 不支持DDL語(yǔ)句
- 不支持子語(yǔ)句
- 不支持UNION 和 UNION ALL
- 不支持特殊INSERT
- 每條INSERT語(yǔ)句只能插入一條數(shù)據(jù),不支持VALUES后有多行數(shù)據(jù)的語(yǔ)句
- 不支持DISTINCT聚合
shardingjdbc使用及踩坑內(nèi)容
1.使用shardingjdbc做分庫(kù)分表
最近公司由于業(yè)務(wù)需要,對(duì)日益增加的數(shù)據(jù)量越來(lái)越無(wú)法容忍,遂作出分庫(kù)分表的決定,考察了幾個(gè)技術(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ù)源,如果做分庫(kù),可配置多個(gè)數(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之類的語(yǔ)句需要做下非空判斷;
2). sqlmap中LONGVARCHER字段不能使用,會(huì)報(bào)序列化異常,可改為VARCHAR類型;
3). union語(yǔ)法不支持,可改為OR查詢(shardingjdbc連OR也不支持,所以建議使用shardingsphere)。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- springboot整合shardingjdbc實(shí)現(xiàn)分庫(kù)分表最簡(jiǎn)單demo
- Java使用Sharding-JDBC分庫(kù)分表進(jìn)行操作
- SpringBoot整合sharding-jdbc實(shí)現(xiàn)自定義分庫(kù)分表的實(shí)踐
- SpringBoot整合sharding-jdbc實(shí)現(xiàn)分庫(kù)分表與讀寫(xiě)分離的示例
- 使用Sharding-JDBC對(duì)數(shù)據(jù)進(jìn)行分片處理詳解
- ShardingSphere jdbc集成多數(shù)據(jù)源的實(shí)現(xiàn)步驟
- SpringBoot集成Sharding Jdbc使用復(fù)合分片的實(shí)踐
- Java ShardingJDBC實(shí)戰(zhàn)演練
相關(guān)文章
java斷點(diǎn)續(xù)傳功能實(shí)例(java獲取遠(yuǎn)程文件)
本文介紹了一種利用 Java 來(lái)實(shí)現(xiàn)斷點(diǎn)續(xù)傳的方法。2013-12-12
java中vector與hashtable操作實(shí)例分享
java中vector與hashtable操作實(shí)例,有需要的朋友可以參考一下2014-01-01
Java基于ReadWriteLock實(shí)現(xiàn)鎖的應(yīng)用
這篇文章主要介紹了Java基于ReadWriteLock實(shí)現(xiàn)鎖的應(yīng)用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-10-10
Java實(shí)現(xiàn)ATM系統(tǒng)超全面步驟解讀建議收藏
這篇文章主要為大家詳細(xì)介紹了用Java實(shí)現(xiàn)簡(jiǎn)單ATM機(jī)功能,文中實(shí)現(xiàn)流程寫(xiě)的非常清晰全面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
Java設(shè)計(jì)模式之命令模式_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
命令模式就是對(duì)命令的封裝,下文中給大家介紹了命令模式類圖中的基本結(jié)構(gòu),對(duì)java設(shè)計(jì)模式之命令模式相關(guān)知識(shí)感興趣的朋友一起看看吧2017-08-08
詳解Spring中Bean后置處理器(BeanPostProcessor)的使用
BeanPostProcessor 接口也被稱為Bean后置處理器,通過(guò)該接口可以自定義調(diào)用初始化前后執(zhí)行的操作方法。本文將詳細(xì)講講它的使用,需要的可以參考一下2022-06-06

