当前位置:   article > 正文

myeclipse下用JDBC链接mysql8出现的错误和解决方案_javamysql驱动升级8.0就报错com.mysql.jdbc.driver

javamysql驱动升级8.0就报错com.mysql.jdbc.driver

mysql8.0.13的改动
1、mysql8.0.13好像改变了配置,之前是在

com.mysql.jdbc.Driver
  • 1

下面的,但是到了8改成了

com.mysql.cj.jdbc.Driver
  • 1

2、链接的Url
之前是直接配置到数据库就可以了,比如我要连rsgl数据库

String url=jdbc:mysql://localhost:3306/rsgl
  • 1

但是现在不行了,会出现这样的错误
在这里插入图片描述
网上查了一下好像说是因为这是由于数据库和系统时区差异所造成的,这要把这句改成

String url = "jdbc:mysql://localhost:3306/rsgl?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC";
  • 1

这样子就可以了

在这里插入图片描述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.
  • 1

如果出现这样要加

useSSL=false
  • 1

这样子就可以了

附完整代码

<%@ 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>

  • 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
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号