Bug #47494 Port in JDBC Connection String is ignored by DriverManager.getConnection()
| Submitted: | 21 Sep 2009 19:07 | Modified: | 1 Oct 2009 9:45 |
|---|---|---|---|
| Reporter: | Jens Nehlmeier | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connector / J | Severity: | S2 (Serious) |
| Version: | 5.1.9 | OS: | Any |
| Assigned to: | Mark Matthews | CPU Architecture: | Any |
[21 Sep 2009 19:07]
Jens Nehlmeier
[22 Sep 2009 6:38]
Tonci Grgin
Hi Jens and thanks for your report. If I understand correctly, your complaint is in that c/J will fall back to default port if no MySQL server is to be found on given port, right? If so, I'd like to think it's a feature, undocumented maybe, rather than a bug.
[22 Sep 2009 8:21]
Jens Nehlmeier
Hi, no I do not mean that c/J 5.1.9 does fall back to default port if no MySQL server is running on the specified port. c/J just does not use the specified port even if a server is running on that port. You can also do the following: - Start MySQL on port 6777 - Specify a connection string "jdbc:mysql://localhost:6777" - c/J 5.1.5 will connect to port 6777 whereas c/J 5.1.9 throws an exception because it trys to connect to default port 3306 where no server is running. => c/J 5.1.9 ignores port 6777 on the connection string.
[22 Sep 2009 9:03]
Tonci Grgin
Verified as described. .Loading JDBC driver 'com.mysql.jdbc.Driver' Done. com.mysql.jdbc.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
[22 Sep 2009 9:08]
Tonci Grgin
Changing triage.
[22 Sep 2009 9:57]
Eric Herman
I notice that on line 344 of com.mysql.jdbc.ConnectionImpl
protected static Connection getInstance(String hostToConnectTo,
int portToConnectTo, Properties info, String databaseToConnectTo,
String url) throws SQLException
that we *are* in fact getting the correct port, so it's not a parsing of the url issue:
hostToConnectTo: localhost
portToConnectTo: 6777
databaseToConnectTo: null
url: jdbc:mysql://localhost:6777
info: {HOST=localhost, HOST.1=localhost, PORT=6777, NUM_HOSTS=1, PORT.1=6777}
Will look deeper.
[22 Sep 2009 10:29]
Eric Herman
patch for BUG#47494 which adds the portToConnectTo when adding a host to the hostList
Attachment: connector-j-5-1-BUG_47494-add_port_to_hostList-1.diff (application/octet-stream, text), 680 bytes.
[22 Sep 2009 13:58]
Mark Matthews
Fixed for 5.1.10
[1 Oct 2009 9:45]
Tony Bedford
An entry has been added to the 5.1.10 changelog: The DriverManager.getConnection() method ignored a non-standard port if it was specified in the JDBC connection string. Connector/J always used the standard port 3306 for connection creation. For example, if the string was jdbc:mysql://localhost:6777, Connector/J would attempt to connect to port 3306, rather than 6777.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.061 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.