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驱动程序(通过serverTimezone配置属性)去使用一个更详细的时间。
问题显示:服务器时区的值无法识别或者代表一个以上的时区,如果想要使用时区支持,必须配置服务器或JDBC驱动程序(通过serverTimezone配置属性)去使用一个更详细的时间。
既然问题已经明白,那么修改代码即可
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/testjdbc?serverTimezone=UTC","root","");
然后就能成功连接Mysql了
问题二:那就是现在Mysql5.5已经不支持用下面这种的方式获取驱动了
Class.forName("com.mysql.jdbc.Driver");
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
上面提示说,已经不赞成加载“com.mysql.jdbc.Driver”这个类,新的驱动类为“com.mysql.cj.jdbc.Driver”。Class.forName("com.mysql.cj.jdbc.Driver");
问题三:java代码将数据写入到数据库中乱码的问题
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/testjdbc?serverTimezone=UTC
&useUnicode=true&characterEncoding=utf-8","root","");
好啦,问题解决了,目前还在学习中