Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
749 views
in Technique[技术] by (71.8m points)

mysql - Android JDBC connection results in ctahttp exception

Im currently trying to establish a connection from my Android app to a MySQL server running on my raspberry pi.

I added the library to android studio correctly by adding it's into the dependencys in the module menu.

I implemented the JDBC-method like this into my program.

 public void readDatabase(String query)throws  Exception{

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");

            connection = DriverManager.getConnection("jdbc:mysql://192.168.0.101/mydb","user","mypassword");

            statement = connection.createStatement();

            resultSet = statement.executeQuery(query);

            System.out.println(resultSet);

        }catch (ClassNotFoundException e){

            e.printStackTrace();

        }finally {
            close();
        }

    }

    private void close(){
        try {
            if (resultSet != null){
                resultSet.close();
            }

            if (statement != null){
                statement.close();
            }

            if ( connection != null){
                connection.close();
            }
        }catch (Exception e){

        }
    }

Every time I fire up the program I get an class not found error. It says :

W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar I/System.out: e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp

I tried to search in different ways for the problem but I can not figure out where the problem is.
I don't even know what the cta class is. Maybe someone can help me out here.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

CTA = China Type Approval, this is something that Mediatek adds in Android for testing purpose.

Your error is happening in DriverManager.getConnection() that probably uses okhttp, apache-http or Socket class in Android's libcore to do its requests.

Mediatek patched these libraries for adding a control of HTTP requests. It tries to load dynamically some methods defined in /system/framework/mediatek-cta.jar but it is probably absent or not accessible on your android device's file system.

I see 5 solutions :

  1. Add an appropriate mediatek-cta.jar via OTA or via adb remount if you are on a custom/rooted ROM
  2. Use another device with the same application's source code (a non- Mediatek based device would not have that issue).
  3. Upgrading your OS via an official OTA update and hope device manufacturer fixed the issue.
  4. Rebuild and customize the OS by yourself with the following modifications
    • Make sure medatek-cta is added to PRODUCT_PACKAGES and PRODUCT_BOOT_JARS
    • Remove the hooks in libcore, okhttp and apache-http.
  5. Contact your OS maintainer's support.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...