当前位置:网站首页>The importance of parameter naming, remember a JDBC parameter conflict
The importance of parameter naming, remember a JDBC parameter conflict
2022-08-05 11:38:00 【yision】
Properties info = new Properties();
info.setProperty("user", "root");
info.setProperty("password", "850656");
info.setProperty("agentID", "1001");
info.setProperty("dbName", "mysql");
// Load a custom driver
Class.forName("com.fanruan.myJDBC.driver.MyDriver");
Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test", info);
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from `student`");
复制代码
如上,由于我重写了JDBC驱动,也就是上文的com.fanruan.myJDBC.driver.MyDriver
.The effect of the rewrite is presumably passedRPC调用客户端的JDBC执行相应操作.由于RPCthe need to call,在DriverManager.getConnection(String url, Properties info)
There are two more parameters encapsulated in the middle,agentID
和dbName
方便 Agent Distribute incoming call messages.测试运行时,It is displayed on the client as follows:
There are programs writtenbug我已经习惯了,但是令我费解的是,我明明在 url
The database is indicated in test
, Why is it wrongTable 'mysql.student' doesn't exist
呢?
It is known that establishing a connection is ultimately calledconnect
方法:
public java.sql.Connection connect(String url, Properties info) throws SQLException {
...
}
复制代码
mysql
的JDBC实现中,会对传入的 Properties 参数进行解析
public ConnectionImpl(HostInfo hostInfo) throws SQLException {
...
this.database = hostInfo.getDatabase();
...
复制代码
public String getDatabase() {
// 在 PropertyKey There is just one called dbname 的键
String database = this.hostProperties.get(PropertyKey.DBNAME.getKeyName());
return isNullOrEmpty(database) ? "" : database;
}
复制代码
Cause would have been parsed as test
的database
:
被覆盖成了mysql
resulting in the error mentioned above.
可以看到进入getConnectionURLInstance
时,dbName
还是驼峰命名.
被处理为connectionURL
之后就变成了dbname
,This is also covered abovedatabase
的前置条件.
至于为什么,That's because of parsingDBNAMEis set to be case insensitive:
边栏推荐
- .NET in-depth analysis of the LINQ framework (6: LINQ execution expressions)
- 【AGC】增长服务1-远程配置示例
- Discover the joy of C language
- 时间格式2020-01-13T16:00:00.000Z中的T和Z分别表示什么,如何处理
- 【深度学习】mmclassification mmcls 实战多标签分类任务教程,分类任务
- PPOCR 检测器配置文件参数详解
- 小红的aba子序列(离散化、二分、dp维护区间最短)
- flutter 服务器返回数据判断是否为空
- 再获殊荣 | 赛宁网安入选2022年度“培育独角兽”企业榜单
- The fuse: OAuth 2.0 four authorized login methods must read
猜你喜欢
随机推荐
Guys, I am a novice. I use flinksql to write a simple count of user visits according to the document, but it ends after executing it once.
Introduction to the Evolution of Data Governance System
STM32 entry development: write XPT2046 resistive touch screen driver (analog SPI)
一张图理解EOS是什么
CenOS MySQL入门及安装
机器学习——逻辑回归
Linux: Remember to install MySQL8 on CentOS7 (blog collection)
[7.29-8.5] Review of wonderful technical blog posts in the writing community
hdu4545 魔法串
Scaling-law和模型结构的关系:不是所有的结构放大后都能保持最好性能
女人是这个世界上最美丽的生命
Android 开发用 Kotlin 编程语言三 循环控制
脱光衣服待着就能减肥,当真有这好事?
SkiaSharp 之 WPF 自绘 投篮小游戏(案例版)
5G NR system messages
Apache APISIX Ingress v1.5-rc1 发布
PPOCR 检测器配置文件参数详解
安全软件Avast与赛门铁克诺顿NortonLifeLock合并获英国批准
深度学习(四)分析问题与调参 理论部分
软件测试之集成测试