当前位置:网站首页>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我已经习惯了,但是令我费解的是,我明明在 urlThe 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:
被覆盖成了mysqlresulting in the error mentioned above.
可以看到进入getConnectionURLInstance时,dbName还是驼峰命名.
被处理为connectionURL之后就变成了dbname,This is also covered abovedatabase的前置条件.
至于为什么,That's because of parsingDBNAMEis set to be case insensitive:
边栏推荐
- 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.
- 训练集Loss收敛,但是测试集Loss震荡的厉害?
- Hands-on Deep Learning_GoogLeNet / Inceptionv1v2v3v4
- 冬日里,28℃的爱情
- What do T and Z in the time format 2020-01-13T16:00:00.000Z represent and how to deal with them
- Naive bayes
- STM32 entry development: write XPT2046 resistive touch screen driver (analog SPI)
- 软件测试之集成测试
- 623. Add a row to a binary tree: Simple binary tree traversal problems
- 小红的aba子序列(离散化、二分、dp维护区间最短)
猜你喜欢
随机推荐
hdu1455 Sticks(搜索+剪枝+剪枝+.....+剪枝)
机器学习——集成学习
163_技巧_Power BI 一键批量建立自定义字段参数
有多一只“手”的机器狗出没?就在昇腾AI开发者创享日·南京站
小红的aba子序列(离散化、二分、dp维护区间最短)
Nature:猪死亡1小时后,器官再次运转
安全软件Avast与赛门铁克诺顿NortonLifeLock合并获英国批准
软件测试之集成测试
LeetCode brush questions (8)
可视化开发必看:智慧城市四大核心技术
623. 在二叉树中增加一行 : 简单二叉树遍历运用题
How OpenHarmony Query Device Type
Http-Sumggling Cache Vulnerability Analysis
lvgl 实现状态提示图标自动对齐补位显示
Google启动通用图像嵌入挑战赛
微信小程序标题栏封装
智源社区AI周刊No.92:“计算复杂度”理论奠基人Juris Hartmanis逝世;美国AI学生九年涨2倍,大学教师短缺;2022智源大会观点报告发布[附下载]
没开发人员,接到开发物联网系统的活儿,干不干?
Detailed explanation of PPOCR detector configuration file parameters
官方发布·2022南京智博会定于10月份在新庄国展召开








![智源社区AI周刊No.92:“计算复杂度”理论奠基人Juris Hartmanis逝世;美国AI学生九年涨2倍,大学教师短缺;2022智源大会观点报告发布[附下载]](/img/e7/df5a17d372a4324d1a2120829d03e9.png)