出于想法,MySQLNonTransientConnectionException:无法创建与数据库服务器的连接

时间:2017-12-11 20:51:58

标签: java android mysql

这是我在Android中的第一个代码之一, 请原谅:D

我有这段代码:

https://pastebin.com/Wbz26gW7

应用程序运行,没有错误,但无法连接到数据库......

并将其写入logcat:

myapplication W/System.err: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

我在互联网上寻求帮助但没有成功:((

1 个答案:

答案 0 :(得分:1)

从您的pastebin

Connection conn = DriverManager.getConnection("jdbc:mysql://sql11.freemysqlhosting.net:3306/sqluname?autoReconnect=true", "sqldbname", "sqlpwd");

来自DriverManager文档(https://docs.oracle.com/javase/7/docs/api/java/sql/DriverManager.html

static Connection getConnection(String url)
static Connection getConnection(String url, Properties info)
static Connection getConnection(String url, String user, String password)

您似乎已在connect方法中混淆了用户名和数据库名称。换句话说,试试

Connection conn = DriverManager.getConnection("jdbc:mysql://sql11.freemysqlhosting.net:3306/sqldbname?autoReconnect=true", "sqluname", "sqlpwd");