0

I am trying to connect my local host database in my android application but I got this error

2021-08-29 15:27:54.859 7973-7973/com.example.invoices D/Amado: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

I looked every where in the internet but non of the solution worked for me

here is my code:

package com.example.invoices
import android.util.Log
import java.sql.SQLException
import java.sql.DriverManager
import java.sql.Connection
object DBConncection {
    @JvmStatic
    fun connection(){
        try{
            val conn = DriverManager.getConnection(
                "jdbc:mysql://127.0.0.1:3306/invoices", "root", "123");
            Log.d("Amado","Success")
        }
        catch (e: SQLException){
            Log.d("Amado",e.toString())
        }
    }
}

I am using android studio, kotlin language, trying to connect to maridb installed as service from xampp the database is working fine

I added mysql connector version 8.0.11 to the project by pasting the jar file in the lib folder->right click on the file and Add as library option

Amado
  • 371
  • 1
  • 16
  • Please [reconsider your use of JDBC in an Android app](https://stackoverflow.com/questions/15853367/jdbc-vs-web-service-for-android). – CommonsWare Aug 29 '21 at 13:37
  • what ? I didn't get what do you mean – Amado Aug 29 '21 at 13:41
  • 2
    I am saying that you should not use JDBC in an Android app. The [Stack Overflow question that I linked to](https://stackoverflow.com/questions/15853367/jdbc-vs-web-service-for-android) contains more information about this. – CommonsWare Aug 29 '21 at 13:53

0 Answers0