简体   繁体   中英

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. The JDBC4Connection constructor use a simple super(), so i refer to the constructor of parent class : 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. But for the "info", Properties typed, i don't know what to put in. The doc says :

hostToConnectTo - the hostname of the database server

portToConnectTo - the port number the server is listening on

info - a Properties[] list holding the user and password

databaseToConnectTo - the database to connect to

url - the URL of the connection

I tried to put keys "user" and "password" but that don't work. Anyone know how to ?

Looking at the source code of com.mysql.jdbc.ConnectionImpl , user & password are fetched from the provided Properties like this:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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