简体   繁体   English

扩展JDBC4Connection类

[英]Extending JDBC4Connection class

I'm searching for creating an extended class of JDBC4Connection to have my proper MySQL Connection JDBC class, and implement some methods. 我正在搜索创建JDBC4Connection的扩展类,以具有适当的MySQL Connection JDBC类,并实现一些方法。 The JDBC4Connection constructor use a simple super(), so i refer to the constructor of parent class : ConnectionImpl. JDBC4Connection构造函数使用一个简单的super(),因此我指的是父类ConnectionImpl的构造函数。

This is : 这是 :

 protected ConnectionImpl(String hostToConnectTo, int portToConnectTo, Properties info, String databaseToConnectTo, String url) throws SQLException 

So, localhost for first, 3306 for second, my database name to fourth, and a complete connection string for the last. 因此,本地主机名第一,第二名3306,我的数据库名第四名,最后一个完整的连接字符串。 But for the "info", Properties typed, i don't know what to put in. The doc says : 但是对于“信息”,属性键入,我不知道要输入什么。文档说:

hostToConnectTo - the hostname of the database server hostToConnectTo-数据库服务器的主机名

portToConnectTo - the port number the server is listening on portToConnectTo-服务器正在侦听的端口号

info - a Properties[] list holding the user and password info-包含用户和密码的Properties []列表

databaseToConnectTo - the database to connect to databaseToConnectTo-要连接的数据库

url - the URL of the connection url-连接的URL

I tried to put keys "user" and "password" but that don't work. 我试图将密钥“ user”和“ password”放进去,但这不起作用。 Anyone know how to ? 有人知道怎么做吗?

Looking at the source code of com.mysql.jdbc.ConnectionImpl , user & password are fetched from the provided Properties like this: 查看com.mysql.jdbc.ConnectionImpl 的源代码 ,从提供的Properties中获取用户名和密码,如下所示:

this.user = info.getProperty(NonRegisteringDriver.USER_PROPERTY_KEY);
this.password = info.getProperty(NonRegisteringDriver.PASSWORD_PROPERTY_KEY);

which are defined as 定义

public static final String USER_PROPERTY_KEY = "user";
public static final String PASSWORD_PROPERTY_KEY = "password";

So your information is correct. 因此,您的信息是正确的。 Would you mind showing the code you actually wrote? 您介意显示您实际编写的代码吗?

But me too, I think this may not be best approach for your problem. 但是我也是,我认为这可能不是解决您问题的最佳方法。 You should probably post this on stackoverflow, too. 您可能也应该将其发布在stackoverflow上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM