当前位置:网站首页>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
边栏推荐
- Zero foundation entry polardb-x: build a highly available system and link the big data screen
- LeetCode_ Gray code_ Medium_ 89. Gray code
- DOM operation
- MySQL information schema learning (II) -- InnoDB table
- Computer network: sorting out common network interview questions (I)
- Unbalance balance (dynamic programming, DP)
- In depth analysis, Android interview real problem analysis is popular all over the network
- Leetcode 30. Concatenate substrings of all words
- Tensorflow2.0 self defined training method to solve function coefficients
- 利用 clip-path 绘制不规则的图形
猜你喜欢
Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
After solving 2961 user feedback, I made such a change
Dark horse -- redis
Vmware虚拟机无法打开内核设备“\\.\Global\vmx86“的解决方法
Introduction to enterprise lean management system
Fast power template for inverse element, the role of inverse element and example [the 20th summer competition of Shanghai University Programming League] permutation counting
C language daily practice - day 22: Zero foundation learning dynamic planning
打家劫舍III[后序遍历与回溯+动态规划]
Mysql Information Schema 學習(一)--通用錶
Understand yolov1 Part II non maximum suppression (NMS) in prediction stage
随机推荐
Leetcode 30. Concatenate substrings of all words
[translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.
LeetCode_格雷编码_中等_89.格雷编码
[translation] supply chain security project in toto moved to CNCF incubator
Unbalance balance (dynamic programming, DP)
1805. 字符串中不同整数的数目
Introduction to enterprise lean management system
CF960G - Bandit Blues(第一类斯特林数+OGF)
C # - realize serialization with Marshall class
反射及在运用过程中出现的IllegalAccessException异常
It's super detailed in history. It's too late for you to read this information if you want to find a job
Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
How to do smoke test
Use of deg2rad and rad2deg functions in MATLAB
Reflection and illegalaccessexception exception during application
社招面试心得,2022最新Android高频精选面试题分享
121. The best time to buy and sell stocks
How can my Haskell program or library find its version number- How can my Haskell program or library find its version number?
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
121. 买卖股票的最佳时机