各位用户为了找寻关于java连不上mysql8.0问题的解决方法的资料费劲了很多周折。这里教程网为您整理了关于java连不上mysql8.0问题的解决方法的相关资料,仅供查阅,以下为您介绍关于java连不上mysql8.0问题的解决方法的详细内容
本文为大家分享了java连不上mysql8.0问题集合,供大家参考,具体内容如下
问题1:client does not support authentication protocol requested by server;…
问题2:unknown initial character set index ‘255' received from server…
问题3:mysql8.0连接必要url语句
问题4:调用方法重复
运行问题1:
解决方法:(3句注意分号,wy123456
是我数据库的密码)
问题2:
解决方法:(重复包删掉)
引入也删掉,只留正确的:
然后重启
一次eclipse!环境才会更新~
关键:mysql8.0要加上这句话:?usessl=false&servertimezone=utc
? 1public
static
string dburl=
"jdbc:mysql://localhost:3306/websql?usessl=false&servertimezone=utc"
;
运行结果:
问题4:
解决方法:(第2次连接,名称得不同)
运行结果:
附上连接dbutil类:
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26package com.cungudafa;
import java.sql.
connection
;
import java.sql.drivermanager;
public
class dbutil {
public
static
string dburl=
"jdbc:mysql://localhost:3306/websql?usessl=false&servertimezone=utc"
;
public
static
string dbusername=
"root"
;
public
static
string dbpassword=
"wy123456"
;
public
static
string jdbcname=
"com.mysql.jdbc.driver"
;
public
static
connection
getcon() throws exception {
class.forname(jdbcname);
connection
con=drivermanager.getconnection(dburl,dbusername,dbpassword);
return
con;
}
public
static
void closecon(
connection
con) {
try {
if (con !=
null
) {
con.
close
();
}
} catch (exception e) {
e.printstacktrace();
}
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
原文链接:https://blog.csdn.net/cungudafa/article/details/86001842