当前位置:网站首页>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
- 腾讯Android面试必问,10年Android开发经验
- Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)
- 保证接口数据安全的10种方案
- 企业精益管理体系介绍
- MySQL information schema learning (II) -- InnoDB table
- C # use Marshall to manually create unmanaged memory in the heap and use
- Li Kou 101: symmetric binary tree
- MySQL must know and learn
- GCC [7] - compilation checks the declaration of functions, and link checks the definition bugs of functions
猜你喜欢
随机推荐
swagger2报错Illegal DefaultValue null for parameter type integer
How can my Haskell program or library find its version number- How can my Haskell program or library find its version number?
【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
学习探索-使用伪元素清除浮动元素造成的高度坍塌
深度剖析原理,看完这一篇就够了
Swagger2 reports an error illegal DefaultValue null for parameter type integer
算法面试经典100题,Android程序员最新职业规划
Use of map (the data of the list is assigned to the form, and the JSON comma separated display assignment)
Benefit a lot, Android interview questions
Lick the dog until the last one has nothing (simple DP)
Mysql Information Schema 学习(一)--通用表
MySQL information schema learning (II) -- InnoDB table
Information System Project Manager - Chapter VIII project quality management
Cereals Mall - Distributed Advanced p129~p339 (end)
Simple application of VBA script in Excel
Vmware虚拟机无法打开内核设备“\\.\Global\vmx86“的解决方法
MySql必知必会学习
Tensorflow2.0 self defined training method to solve function coefficients
Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
Chic Lang: attributeerror: partially initialized module 'CV2' has no attribute 'GAPI_ wip_ gst_ GStreamerPipe








