Hibernate: Connect to MySQL without Username or Password
-
06-07-2019 - |
Question
I am developing a hibernate application that connects to a MySQL database.
The customers would like to only specify a connection string, ie:
jdbc:mysql://username:passwd@server:port/db_name
However, Hibernate will not connect using just this string. It also wants the username and password connection properties set. Is there any way around this?
Thanks
Solution
Hibernate itself does not "want username and password connection properties set"; it just passes them to your JDBC driver. Depending on what database connection pool you're using user / password may be specified via different methods.
MySQL JDBC driver allows you to specify username / password in the URL, but not in the format you've shown in your question. They should be specified as parameters instead:
jdbc:mysql://server:port/db_name?user=username&password=passwd
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow