简体   繁体   中英

connect mysql server to an android app (java) error

i have been trying to connect to my mysql server using java and Android studio but no luck, i looked up all over the internet but still no success.. my code:

    CharSequence text = "Trying...";
int duration = Toast.LENGTH_SHORT;
Context context = getApplicationContext();
Toast wel = Toast.makeText(context, text, duration);
Toast err = Toast.makeText(context, "Conntection Failed", duration);
Toast suc = Toast.makeText(context, "Conntection Success", duration);

Connection con = null;
String url = "jdbc:mysql://...../?user=....";
     if(con == null) {
         try {
             DriverManager.getConnection(url, "username", "pass");
             suc.show();
         }catch (SQLException ex){
            // handle any errors
             err = Toast.makeText(context, ex.getMessage(), duration);
             err.show();
            }
        }

I already used this command:

<uses-permission android:name="android.permission.INTERNET"/>

and I downloaded the jdbc connector.. my error is: "could not create connection to database server" any idea?

if the database is on the local machine, the port is needed to connect. MYSQL usually uses the 3306 port.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM