在学习到JDBC时下载了现下最新版的mysql(mysql-8.0.17-winx64)下载链接:https://cdn.mysql.com//Downloads/MySQLInstaller/mysql-installer-community-8.0.17.0.msi
mysql-connector-java-8.0.17.jar 下载链接:http://central.maven.org/maven2/mysql/mysql-connector-java/8.0.17/mysql-connector-java-8.0.17.jar
坑1:
发现通过“com.mysql.jdbc.Driver”连接不上
解决:原来是8.0以上版本改为了:“com.mysql.cj.jdbc.Driver”
坑2:
java.sql.SQLException: The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
解决:将"jdbc:mysql://localhost:3306/mysql"改为"jdbc:mysql://localhost:3306/mydb?serverTimezone=UTC"
查看mysql的时区:
坑3:
前两个坑通过百度就可以轻易查到,这个坑并没有找到。。。
Android Studio插件:Database Navigator,特别好用,安装方式这里不赘述了,百度即可查到(貌似目前新版本中自带)
坑来了:接好!
通过以下方式创建连接:
报错:
Cannot connect to "Connection".The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
和坑2一样,可是在这里怎么解决呢?百度找不到,各种设置里也找不到。。。通过各种尝试终于:解决了!
解决如下:
划重点!划重点!划重点!
创建连接时不要选择具体数据库类型
将代码中的url填入即可!!!
附:
1. mysql各个版本驱动jar包下载:http://central.maven.org/maven2/mysql/mysql-connector-java/