0
votes

I'm trying to establish an SSL connection from java application to mysql server. Following are the setup details.

  • java 8
  • mysql server version: 5.7.28
  • mysql-connector-java-8.0.12
  • connection string: jdbc:mysql://localhost:3306/carbon_mysql?autoReconnect=true&useSSL=true&requireSSL=true

But when I try to connect through the java application, following exception is thrown.

Caused by: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near '=true&requireSSL=true'.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:59)
at com.mysql.cj.conf.ConnectionUrlParser.processKeyValuePattern(ConnectionUrlParser.java:524)
at com.mysql.cj.conf.ConnectionUrlParser.parseQuerySection(ConnectionUrlParser.java:496)
at com.mysql.cj.conf.ConnectionUrlParser.getProperties(ConnectionUrlParser.java:621)
at com.mysql.cj.conf.ConnectionUrl.collectProperties(ConnectionUrl.java:302)
at com.mysql.cj.conf.ConnectionUrl.<init>(ConnectionUrl.java:287)
at com.mysql.cj.conf.url.SingleConnectionUrl.<init>(SingleConnectionUrl.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.cj.util.Util.handleNewInstance(Util.java:210)
at com.mysql.cj.util.Util.getInstance(Util.java:185)
at com.mysql.cj.util.Util.getInstance(Util.java:192)
at com.mysql.cj.conf.ConnectionUrl.getConnectionUrlInstance(ConnectionUrl.java:189)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:201)
... 83 more
1
Please check your database URL is correctPramodya Mendis
What happens when you turn the JDBC url into jdbc:mysql://localhost:3306/carbon_mysql?autoReconnect=true&amp;useSSL=true&amp;requireSSL=true so it is url-encoded?Gimby
Post the actual code.user207421

1 Answers

0
votes

Try changing your connection url to

jdbc:mysql://localhost:3306/carbon_mysql?autoReconnect=true&useSSL=true&requireSSL=true&verifyServerCertificate=true

You also have to make sure that you have granted ssl on mysql. log in as root in the MySQL server, and run the queries given below:

GRANT USAGE ON *.* TO 'root'@'%' REQUIRE SSL; 
FLUSH PRIVILEGES;