使用限制
JDBC未支持列表
- Sharding-JDBC暫時未支持不常用的JDBC方法。
DataSource接口
- 不支持timeout相關操作
Connection接口
- 不支持存儲過程,函數,游標的操作
- 不支持執行native的SQL
- 不支持savepoint相關操作
- 不支持Schema/Catalog的操作
- 不支持自定義類型映射
Statement和PreparedStatement接口
- 不支持返回多結果集的語句(即存儲過程,非SELECT多條數據)
- 不支持國際化字符的操作
對于ResultSet接口
- 不支持對于結果集指針位置判斷
- 不支持通過非next方法改變結果指針位置
- 不支持修改結果集內容
- 不支持獲取國際化字符
- 不支持獲取Array
JDBC 4.1
- 不支持JDBC 4.1接口新功能
- 查詢所有未支持方法,請閱讀com.dangdang.ddframe.rdb.sharding.jdbc.unsupported包。
SQL語句限制
- 不支持DDL語句
- 不支持子語句
- 不支持UNION 和 UNION ALL
- 不支持特殊INSERT
- 每條INSERT語句只能插入一條數據,不支持VALUES后有多行數據的語句
- 不支持DISTINCT聚合
shardingjdbc使用及踩坑內容
1.使用shardingjdbc做分庫分表
最近公司由于業務需要,對日益增加的數據量越來越無法容忍,遂作出分庫分表的決定,考察了幾個技術方案后,決定使用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為數據源,如果做分庫,可配置多個數據源;不分表的表不用在此做配置--> < 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.踩坑內容
1). 用于分表的列在sql中不能為空,所以像insert之類的語句需要做下非空判斷;
2). sqlmap中LONGVARCHER字段不能使用,會報序列化異常,可改為VARCHAR類型;
3). union語法不支持,可改為OR查詢(shardingjdbc連OR也不支持,所以建議使用shardingsphere)。
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/Farrell_zeng/article/details/52958181