1

There are codes collected from internet to connect mysql server via JDBC and the error logs.

try {
                Class.forName("com.mysql.cj.jdbc.Driver"); 
                conn = DriverManager.getConnection("jdbc:mysql://XXX.XX.XXX.XXX:3306/androidapp","XXX", "XXXXX");
                }

there are two lines at the end.

01-21 22:53:48.713 5823-5946/com.stellaris.practice E/AndroidRuntime: FATAL EXCEPTION: Thread-5
    Process: com.stellaris.practice, PID: 5823
    java.lang.UnsupportedOperationException
        at java.util.regex.Matcher.group(Matcher.java:383)
        at com.mysql.cj.conf.ConnectionUrlParser.isConnectionStringSupported(ConnectionUrlParser.java:152)
        at com.mysql.cj.conf.ConnectionUrl.acceptsUrl(ConnectionUrl.java:258)
        at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:195)
        at java.sql.DriverManager.getConnection(DriverManager.java:569)
        at java.sql.DriverManager.getConnection(DriverManager.java:219)
        at com.stellaris.functions.DBUtils.getConnection(DBUtils.java:21)
        at com.stellaris.functions.DBUtils.getUserInfoByName(DBUtils.java:33)
        at com.stellaris.practice.LoginActivity$2.run(LoginActivity.java:91)
        at java.lang.Thread.run(Thread.java:760)

these two

 java.lang.UnsupportedOperationException
        at java.util.regex.Matcher.group(Matcher.java:383)
        at com.mysql.cj.conf.ConnectionUrlParser.isConnectionStringSupported(ConnectionUrlParser.java:152)

trace it

public static boolean isConnectionStringSupported(String connString) {
        if (connString == null) {
            throw (WrongArgumentException)ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("ConnectionString.0"));
        } else {
            Matcher matcher = SCHEME_PTRN.matcher(connString);
            return matcher.matches() && Type.isSupported(decode(matcher.group("scheme")));
        }
    }

The matcher.group() pass String

return matcher.matches() && Type.isSupported(decode(matcher.group("scheme")));

But this pass INT

public String group(int group) {
        ensureMatch();
        int from = matchOffsets[group * 2];
        int to = matchOffsets[(group * 2) + 1];
        if (from == -1 || to == -1) {
            return null;
        } else {
            return input.substring(from, to);
        }
    }

This is the error

java.lang.UnsupportedOperationException

There is a same problem as mine. But it has 0 answer :( Android connection error java.lang.UnsupportedOperationException

I write some test codes. And it works.

package com.stellaris.test;
import java.sql.DriverManager;

public class test {
    private static String ip = "XXX.XXX.XXX.XXX";
    private static String dbname = "XXX";
    private static String url = "jdbc:mysql://" + ip + "/"+ dbname +"?useSSL=false&serverTimezone=UTC&autoReconnect=true&failOverReadOnly=false  ";
    private static String driver = "com.mysql.cj.jdbc.Driver";
    private static String username = "XXX";
    private static String password = "XXXXXX";

    public static void main(String[] args) throws Exception {
        Class.forName(driver).newInstance();

        System.out.println(DriverManager.getConnection(url, username, password));

    }
}

I really don't know why it happened. They are almost the same. And the error is so strange. When I press the button and getConnection() run, the app exits at once.
dependency:

implementation files('libs/mysql-connector-java-8.0.12.jar')
implementation files('libs/protobuf-java-3.6.1.jar')

Luckily, I almost solve the problem via adjust the JDBC version . This is my answer in the linked problem.

I have a same problem as yours. When I find a guy meeting a same proble with me in StackOverFlow, I am so exciting. But When I find there is 0 answer, I feel so hopeless and sad. (ಥ_ಥ) After painful tryings , I replace mysql-connector-java 8.x with 5.1.47. Then the confusing errors java.lang.UnsupportedOperationException disappear. ( But I don't know whether other bugs will appear. At least other bugs appear at sql connect stage and they look resolvable. I think it may be related with SDK version? ) hope I can help you :)

MoWa
  • 21
  • 5
  • I'm also having the same problem, it was debugging, but it looks like some problem, in the native call of the `Pattern` class, because if you put the pattern "`(?[\\w:%]+).*`", Here [test regex java](https://www.freeformatter.com/java-regex-tester.html), it works. I'm going back to the JDBC driver version, thanks for sharing your experience – Marco Giovanni Mar 22 '19 at 14:00
  • this error `matcher.group("scheme")`. This ok `matcher.group(1)` I believe there is some error in the native function `private static native int getMatchedGroupIndex0(long patternAddr, String name)`; – Marco Giovanni Mar 22 '19 at 14:34
  • I opened a mysql ticket, if you want to follow [link](https://bugs.mysql.com/bug.php?id=94754) – Marco Giovanni Mar 22 '19 at 15:13

0 Answers0