Reputation: 801
Here is my connection URL:
jdbc:mysql://mydbhost:3306/mydatabase?user=username&password=%u16*!ypK@WrUQbr
When i call
DriverManager.getConnection()
with current URL i'm catching exception:
ava.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "u1"
If connection URL not contain % everything works.
i have found some info about this issue, and there recommend to do next conversion :
replaceAll("%(?![0-9a-fA-F]{2})", "%25")
With this conversion i have error:
Access denied for user(incorrect password)
Can somebody help to convert url correctly?
Upvotes: 6
Views: 7801
Reputation: 801
I have tried as "Carlos Heuberger" recommended, call getConnection(String url, String user, String password)
In this style it works, and from my view looks more clear instead of build one huge URL with all parameters included
Upvotes: 0
Reputation: 16498
Try it with below string, where all reserved characters in your password are replaced with the appropriate percent-encoded value:
% : %25
* : %2A
! : %21
@ : %40
"jdbc:mysql://mydbhost:3306/mydatabase?user=username&password=%25u16%2A%21ypK%40WrUQbr"
More information about percent-encoding Wikipedia
Upvotes: 12