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"