当前位置:网站首页>终于可以一行代码也不用改了!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 驱动
六、结语
边栏推荐
- Master Xuan joined hands with sunflower to remotely control enabling cloud rendering and GPU computing services
- R语言使用rchisq函数生成符合卡方分布的随机数、使用plot函数可视化符合卡方分布的随机数(Chi Square Distribution)
- [matlab] Simulink the input and output variables of the same module cannot have the same name
- R language uses DT function to generate t-distribution density function data and plot function to visualize t-distribution density function data
- 第五期个人能力认证考核通过名单公布
- Understanding disentangling in β- VAE paper reading notes
- Modulenotfounderror: no module named 'PIL' solution
- 今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发
- Translation D28 (with AC code POJ 26:the nearest number)
- 倒计时2天|腾讯云消息队列数据接入平台(Data Import Platform)直播预告
猜你喜欢
受益匪浅,安卓面试问题
Intelligent supply chain management system solution for hardware and electromechanical industry: digital intelligent supply chain "creates new blood" for traditional industries
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
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
Yutai micro rushes to the scientific innovation board: Huawei and Xiaomi fund are shareholders to raise 1.3 billion
Cereals Mall - Distributed Advanced p129~p339 (end)
安装Mysql报错:Could not create or access the registry key needed for the...
[depth first search] Ji suanke: a joke of replacement
Solution of intelligent management platform for suppliers in hardware and electromechanical industry: optimize supply chain management and drive enterprise performance growth
Unlock 2 live broadcast themes in advance! Today, I will teach you how to complete software package integration Issues 29-30
随机推荐
R语言ggplot2可视化时间序列柱形图:通过双色渐变配色颜色主题可视化时间序列柱形图
Lucun smart sprint technology innovation board: annual revenue of 400million, proposed to raise 700million
C language daily practice - day 22: Zero foundation learning dynamic planning
零基础入门PolarDB-X:搭建高可用系统并联动数据大屏
Benefit a lot, Android interview questions
PMP每日一练 | 考试不迷路-7.6
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
AUTOCAD——中心线绘制、CAD默认线宽是多少?可以修改吗?
Based on butterfly species recognition
Synchronous development of business and application: strategic suggestions for application modernization
[depth first search] Ji suanke: Square
An error occurs when installing MySQL: could not create or access the registry key needed for the
map的使用(列表的数据赋值到表单,json逗号隔开显示赋值)
Helm deploy etcd cluster
Openmv4 learning notes 1 --- one click download, background knowledge of image processing, lab brightness contrast
MRO工业品企业采购系统:如何精细化采购协同管理?想要升级的工业品企业必看!
How to improve website weight
Precautions for binding shortcut keys of QPushButton
It's super detailed in history. It's too late for you to read this information if you want to find a job
Php+redis realizes the function of canceling orders over time