赞
踩
mysql8.0.13的改动
1、mysql8.0.13好像改变了配置,之前是在
com.mysql.jdbc.Driver
下面的,但是到了8改成了
com.mysql.cj.jdbc.Driver
2、链接的Url
之前是直接配置到数据库就可以了,比如我要连rsgl数据库
String url=jdbc:mysql://localhost:3306/rsgl
但是现在不行了,会出现这样的错误
网上查了一下好像说是因为这是由于数据库和系统时区差异所造成的,这要把这句改成
String url = "jdbc:mysql://localhost:3306/rsgl?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC";
这样子就可以了
3、我没遇到的
看了别人的文章好像还可能出现
WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements <br>SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate<br> property is set to 'false'.You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate<br> verification.
如果出现这样要加
useSSL=false
这样子就可以了
附完整代码
<%@ page contentType="text/html; charset=GB2312" language="java"%> <%@ page import="java.sql.*"%> <%@ page import="com.mysql.jdbc.Driver" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>SQL Server</title> </head> <body> <% Connection conn = null; try { Class.forName("com.mysql.cj.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/rsgl?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC"; String user = "root"; String password = "123"; conn = DriverManager.getConnection(url,user,password); out.println("数据库链接成功<br>"); } catch(ClassNotFoundException e) { out.println("!"+e.getMessage()); } finally { try { if(conn!=null) { conn.close(); out.println("数据库关闭"); } } catch(Exception e) { out.println(e.getMessage()); } } %> </body> </html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。