0
    url = "jdbc:postgres://cvzsfhiy:**********.db.elephantsql.com/cvzsfhiy"
    user = "cvzsfhiy"
    password = "************"

    var conn1: Connection? = null
    var conn2: Connection? = null
    var conn3: Connection? = null

    button.setOnClickListener {
        try {
            Class.forName("org.postgresql.Driver")

            conn1 = DriverManager.getConnection(url, user, password)
            if (conn1 != null) {
                println("Connected to the database test1")
                tv.text = "Connection1"
            }

            // connect way #2
            val url2 = "jdbc:postgres://cvzsfhiy:*********?user=cvzsfhiy&password=***********"
            conn2 = DriverManager.getConnection(url2)
            if (conn2 != null) {
                println("Connected to the database test2")
                tv.text = "Connection2"
            }

            // connect way #3
            val url3 = "jdbc:postgres://cvzsfhiy:************y.db.elephantsql.com/cvzsfhiy"
            val info = Properties()
            info["user"] = "cvzsfhiy"
            info["password"] = "***************"
            conn3 = DriverManager.getConnection(url3, info)
            if (conn3 != null) {
                println("Connected to the database test3")
                tv.text = "Connection3"
            }
        } catch (ex: SQLException) {
            tv.text = "An error occurred. Maybe user/password is invalid"
            ex.printStackTrace()
        } catch (e: ClassNotFoundException) {
            tv.text = "Class Not Found"
            e.printStackTrace()
        }
    }
}

This is my instance for the elephant sql I'm getting SQLException error,Couldn't connect to the Database from Android App giving "java.sql.SQLException: No suitable driver found for --"url Link"

sakurai
  • 78
  • 7
  • Please [reconsider your use of JDBC on Android](https://stackoverflow.com/questions/15853367/jdbc-vs-web-service-for-android?r=Saves_AllUserSaves). – CommonsWare May 07 '23 at 17:24

1 Answers1

0

The url in the example code is mispelled (the jdbc:postgres: part of it).

Please see PostgreSQL documentation for the right spelling.

Michal
  • 2,353
  • 1
  • 15
  • 18