当前位置:网站首页>终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
2022-07-06 11:29:00 【InfoQ】
一、背景
二、痛点
三、契机
四、实现
org.apache.shardingsphere.driver.ShardingSphereDriver- 以
jdbc:shardingsphere: 为前缀
- 配置文件:
xxx.yaml,配置文件格式与 YAML 配置一致
- 配置文件加载规则:
- 无前缀表示从绝对路径加载配置文件
- classpath: 前缀表示从类路径中加载配置文件
五、使用步骤
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";// 以 HikariCP 为例 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 驱动
六、结语
边栏推荐
- Computer network: sorting out common network interview questions (I)
- Three years of Android development, Android interview experience and real questions sorting of eight major manufacturers during the 2022 epidemic
- Interview assault 63: how to remove duplication in MySQL?
- Actf 2022 came to a successful conclusion, and 0ops team won the second consecutive championship!!
- R language uses DT function to generate t-distribution density function data and plot function to visualize t-distribution density function data
- Interface test tool - postman
- Problems encountered in using RT thread component fish
- QPushButton绑定快捷键的注意事项
- Documents to be used in IC design process
- usb host 驱动 - UVC 掉包
猜你喜欢

Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)

AutoCAD - what is the default lineweight for centerline drawing and CAD? Can I modify it?

安装Mysql报错:Could not create or access the registry key needed for the...

基于蝴蝶种类识别

Intelligent supply chain management system solution for hardware and electromechanical industry: digital intelligent supply chain "creates new blood" for traditional industries

The list of people who passed the fifth phase of personal ability certification assessment was published
时钟轮在 RPC 中的应用

Pychrm Community Edition calls matplotlib pyplot. Solution of imshow() function image not popping up

谷粒商城--分布式高级篇P129~P339(完结)
![[paper notes] transunet: transformers make strongencoders for medical image segmentation](/img/21/3d4710024248b62495e2681ebd1bc4.png)
[paper notes] transunet: transformers make strongencoders for medical image segmentation
随机推荐
How can my Haskell program or library find its version number- How can my Haskell program or library find its version number?
打家劫舍III[后序遍历与回溯+动态规划]
A method of removing text blur based on pixel repair
The second day of rhcsa study
helm部署etcd集群
Looting iii[post sequence traversal and backtracking + dynamic planning]
Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
Computer network: sorting out common network interview questions (I)
Swagger2 reports an error illegal DefaultValue null for parameter type integer
Word如何显示修改痕迹
驼峰式与下划线命名规则(Camel case With hungarian notation)
R language ggplot2 visualization: use ggviolin function of ggpubr package to visualize violin diagram
LeetCode-1279. 红绿灯路口
倒计时2天|腾讯云消息队列数据接入平台(Data Import Platform)直播预告
Digital "new" operation and maintenance of energy industry
Three years of Android development, Android interview experience and real questions sorting of eight major manufacturers during the 2022 epidemic
Solution of commercial supply chain management platform for packaging industry: layout smart supply system and digitally integrate the supply chain of packaging industry
Leetcode topic [array] - 119 Yang Hui triangle II
A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo
zabbix 代理服务器 与 zabbix-snmp 监控