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我得到SQLException错误,无法连接到数据库从Android应用程序给出“java.sql.SQLException:没有找到合适的驱动程序--“url链接”
1条答案
按热度按时间yruzcnhs1#
示例代码中的
url
拼写错误(jdbc:postgres:
部分)。请参阅PostgreSQL documentation以获得正确的拼写。