当前位置:网站首页>终于可以一行代码也不用改了!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 驱动
六、结语
边栏推荐
- 使用map函数、split函数一行键入多个元素
- Sanmian ant financial successfully got the offer, and has experience in Android development agency recruitment and interview
- 受益匪浅,安卓面试问题
- tensorflow和torch代码验证cuda是否安装成功
- map的使用(列表的数据赋值到表单,json逗号隔开显示赋值)
- Openmv4 learning notes 1 --- one click download, background knowledge of image processing, lab brightness contrast
- Graffiti intelligence is listed on the dual main board in Hong Kong: market value of 11.2 billion Hong Kong, with an annual revenue of 300 million US dollars
- The dplyr package of R language performs data grouping aggregation statistical transformations and calculates the grouping mean of dataframe data
- 主从搭建报错:The slave I/O thread stops because master and slave have equal MySQL serv
- Excel 中VBA脚本的简单应用
猜你喜欢

黑马--Redis篇
![Looting iii[post sequence traversal and backtracking + dynamic planning]](/img/9b/e9eeed138e46afdeed340bf2629ee1.png)
Looting iii[post sequence traversal and backtracking + dynamic planning]
受益匪浅,安卓面试问题

渲大师携手向日葵,远控赋能云渲染及GPU算力服务

About static type, dynamic type, ID, instancetype

如何提高网站权重

Yutai micro rushes to the scientific innovation board: Huawei and Xiaomi fund are shareholders to raise 1.3 billion

Php+redis realizes the function of canceling orders over time

Based on butterfly species recognition

pychrm社区版调用matplotlib.pyplot.imshow()函数图像不弹出的解决方法
随机推荐
C # - realize serialization with Marshall class
CPU负载很低,loadavg很高处理方法
Use of deg2rad and rad2deg functions in MATLAB
今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发
First day of rhcsa study
Take a look at how cabloyjs workflow engine implements activiti boundary events
2022.2.12
The list of people who passed the fifth phase of personal ability certification assessment was published
Multithreading Basics: basic concepts of threads and creation of threads
【论文笔记】TransUNet: Transformers Make StrongEncoders for Medical Image Segmentation
The second day of rhcsa study
Black Horse - - Redis Chapter
When visual studio code starts, it prompts "the code installation seems to be corrupt. Please reinstall." Solution to displaying "unsupported" information in the title bar
Use of map (the data of the list is assigned to the form, and the JSON comma separated display assignment)
[paper notes] transunet: transformers make strongencoders for medical image segmentation
Druid 数据库连接池 详解
安装Mysql报错:Could not create or access the registry key needed for the...
How to improve website weight
Help improve the professional quality of safety talents | the first stage of personal ability certification and assessment has been successfully completed!
QPushButton绑定快捷键的注意事项