mit-pdos / noria-mysql

MySQL/MariaDB protocol shim for Noria
MIT License
67 stars 15 forks source link

Java application can not use noria-mysql adapter #15

Open lipinskipawel opened 4 years ago

lipinskipawel commented 4 years ago

Hey! I was trying to run Java application with Noria but I got an exception

Exception in thread "main" java.sql.SQLNonTransientConnectionException: CLIENT_SECURE_CONNECTION is required
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:79)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:270)
    at com.example.demo.DemoApplication.main(DemoApplication.java:12)
Caused by: com.mysql.cj.exceptions.UnableToConnectException: CLIENT_SECURE_CONNECTION is required
    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:61)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
    at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:111)
    at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1342)
    at com.mysql.cj.NativeSession.connect(NativeSession.java:157)
    at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
    ... 6 more

Steps to reproduce:

Some java app example main method ``` Class.forName("com.mysql.cj.jdbc.Driver"); final String name = DriverManager .getConnection("jdbc:mysql://127.0.0.1/") .prepareStatement("select * from Cats") .executeQuery() .getString("name"); System.out.println(name); ``` pom.xml ``` mysql mysql-connector-java 8.0.20 ```

My questions:

  1. Is they any solution to resolve this error above?
  2. How to interact with noria-mysql adapter through the Java code?
  3. What is the general idea of interacting with noria-mysql? (besides mysql -h 127.0.0.1 nothing is working for me)
jonhoo commented 4 years ago

Ah, yes, msql-srv (which provides the MySQL interface) does not currently support the SSL handshake, and thus only supports non-encrypted connections. If the Java library requires a secure connection ("CLIENT_SECURE_CONNECTION is required"), and that can't be disabled, then the way forward would be to add SSL support to msql-srv. Adding it shouldn't be too difficult, though I don't personally have the bandwidth to do so at the moment. If you want to take a stab at writing a PR, I'd be happy to take a look! See also https://github.com/jonhoo/msql-srv/issues/10 which also has some Java-related problems.