当前位置:网站首页>Finally, there is no need to change a line of code! Shardingsphere native driver comes out
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
2022-07-06 19:41:00 【InfoQ】
One 、 background
Two 、 Pain points
3、 ... and 、 chance
Four 、 Realization
org.apache.shardingsphere.driver.ShardingSphereDriver
- With
jdbc:shardingsphere
: The prefix
- The configuration file :
xxx.yaml
, The configuration file format is the same as YAML Consistent configuration
- Configuration file loading rules :
- No prefix means that the configuration file is loaded from the absolute path
- classpath: Prefix means loading configuration file from classpath
5、 ... and 、 Use steps
Class.forName("org.apache.shardingsphere.driver.ShardingSphereDriver");
String jdbcUrl = "jdbc:shardingsphere:classpath:config.yaml";
String sql = "SELECT i.* FROM t_order o JOIN t_order_item i ON o.order_id=i.order_id WHERE o.user_id=? AND o.order_id=?";
try (
Connection conn = DriverManager.getConnection(jdbcUrl);
PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, 10);
ps.setInt(2, 1000);
try (ResultSet rs = preparedStatement.executeQuery()) {
while(rs.next()) {
// ... }
}
}
String driverClassName = "org.apache.shardingsphere.driver.ShardingSphereDriver";
String jdbcUrl = "jdbc:shardingsphere:classpath:config.yaml";// With HikariCP For example HikariDataSource dataSource = new HikariDataSource();
dataSource.setDriverClassName(driverClassName);
dataSource.setJdbcUrl(jdbcUrl);
String sql = "SELECT i.* FROM t_order o JOIN t_order_item i ON o.order_id=i.order_id WHERE o.user_id=? AND o.order_id=?";
try (
Connection conn = dataSource.getConnection();
PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, 10);
ps.setInt(2, 1000);
try (ResultSet rs = preparedStatement.executeQuery()) {
while(rs.next()) {
// ... }
}
}
- JDBC drive
6、 ... and 、 Conclusion
边栏推荐
- Phoenix Architecture 3 - transaction processing
- Swagger2 reports an error illegal DefaultValue null for parameter type integer
- [translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.
- Tencent Android interview must ask, 10 years of Android development experience
- Lick the dog until the last one has nothing (simple DP)
- 学习探索-使用伪元素清除浮动元素造成的高度坍塌
- Recursive implementation of department tree
- Dark horse -- redis
- 凤凰架构2——访问远程服务
- 学习探索-无缝轮播图
猜你喜欢
面试突击63:MySQL 中如何去重?
【基础架构】Flink/Flink-CDC的部署和配置(MySQL / ES)
Druid database connection pool details
冒烟测试怎么做
黑馬--Redis篇
如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!
Hudi vs Delta vs Iceberg
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
How to access localhost:8000 by mobile phone
【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...
随机推荐
How can my Haskell program or library find its version number- How can my Haskell program or library find its version number?
Introduction to enterprise lean management system
Sanmian ant financial successfully got the offer, and has experience in Android development agency recruitment and interview
Black Horse - - Redis Chapter
USB host driver - UVC swap
谷粒商城--分布式高级篇P129~P339(完结)
今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发
【pytorch】yolov5 训练自己的数据集
LeetCode-1279. Traffic light intersection
手把手教你学会js的原型与原型链,猴子都能看懂的教程
[translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.
Is not a drawable (color or path): the vector graph downloaded externally cannot be called when it is put into mipmap, and the calling error program crashes
MySql必知必会学习
Zero foundation entry polardb-x: build a highly available system and link the big data screen
算法面试经典100题,Android程序员最新职业规划
《数字经济全景白皮书》保险数字化篇 重磅发布
short i =1; I=i+1 and short i=1; Difference of i+=1
Tencent Android interview must ask, 10 years of Android development experience
[translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system
[play with Linux] [docker] MySQL installation and configuration