使用限制
JDBC未支持列表
- Sharding-JDBC暫時(shí)未支持不常用的JDBC方法。
DataSource接口
- 不支持timeout相關(guān)操作
Connection接口
- 不支持存儲(chǔ)過(guò)程,函數(shù),游標(biāo)的操作
- 不支持執(zhí)行native的SQL
- 不支持savepoint相關(guān)操作
- 不支持Schema/Catalog的操作
- 不支持自定義類(lèi)型映射
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接口新功能
- 查詢(xún)所有未支持方法,請(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包:
1
2
3
4
5
6
7
8
9
10
|
< 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 > |
分表配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
<? 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之類(lèi)的語(yǔ)句需要做下非空判斷;
2). sqlmap中LONGVARCHER字段不能使用,會(huì)報(bào)序列化異常,可改為VARCHAR類(lèi)型;
3). union語(yǔ)法不支持,可改為OR查詢(xún)(shardingjdbc連OR也不支持,所以建議使用shardingsphere)。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://blog.csdn.net/Farrell_zeng/article/details/52958181