0

I'm trying to execute a mysql query in my java application using JDBC but instead of a query result, I get an error

java.lang.UnsupportedOperationExeption.

I did these steps in my app:

  1. Added mysql Connector.jar (version 8) in libs directory
  2. Added <uses-permission android:name="android.permission.INTERNET" /> to manifest
  3. Updated gradel, jdk to latest version
  4. Changed api to 32 or 21 but it didn't work

The Mysql user privileges and tables are ok. I launched my app in Android Studio

Here is my code:

public class MainActivity extends AppCompatActivity {

    TextView query_result_TextView, Error_textview;
    Button show_btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        query_result_TextView = (TextView) findViewById(R.id.textView);
        Error_textview = (TextView) findViewById(R.id.textView2);
        show_btn = (Button) findViewById(R.id.showbtn);

        show_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    Class.forName("com.mysql.jdbc.Driver").newInstance();
                    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/adl","testuser","12345678");
                    Statement stmt = con.createStatement();
                    ResultSet rs = stmt.executeQuery("SELECT * FROM test ;");

                    query_result_TextView.setText(rs.toString());
                }
                catch (Exception ex) {
                    Error_textview.setText(ex.toString());
//                    java.lang.UnsupportedOperationExeption
                }
            }
        });

    }
}

I tried soooo much, but this error didn't get resolved.

Please help !

NOTE: i tried to coonect with eclipse IDE with same syntax and in Eclipse worked pefectly!!!! is there a option in Android Studio that's avoiding to connect?

  • Please [reconsider your use of JDBC in an Android app](https://stackoverflow.com/questions/15853367/jdbc-vs-web-service-for-android). – CommonsWare Jan 07 '23 at 23:28
  • i also used doinbackground and other overwrited method for this app but doesn't worked either – Captain_zed Jan 08 '23 at 14:04

0 Answers0