0

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?

adt5854
  • 1
  • 2
  • It's generally a bad idea to have a public MySQL server that anyone can connect to. If you're writing an app, consider having some kind of API layer for security. – tadman Oct 05 '20 at 01:59
  • Please read: [JDBC vs Web Service for Android](https://stackoverflow.com/q/15853367/295004) – Morrison Chang Oct 05 '20 at 02:15

1 Answers1

0

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

Umer Khalid
  • 330
  • 2
  • 16