gpt4 book ai didi

java - 出于想法,MySQLNonTransientConnectionException : Could not create connection to database server

转载 作者:行者123 更新时间:2023-11-29 10:29:04 24 4
gpt4 key购买 nike

这是我在 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.

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

最佳答案

来自您的粘贴箱

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)

看来您在连接方法中混淆了用户名和数据库名称。换句话说,尝试

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

关于java - 出于想法,MySQLNonTransientConnectionException : Could not create connection to database server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47761212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com