2 ronaldo12 RONALDO12 于 2016.09.09 01:13 提问

java与mysql连接出现的问题

Fri Sep 09 00:56:14 CST 2016 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 SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate 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 verification.
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:875)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1712)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1228)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:806)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.jakey.util.DbUtil.getCon(DbUtil.java:19)
at com.jakey.util.DbUtil.main(DbUtil.java:31
代码
package com.jakey.util;

import java.sql.Connection;
import java.sql.DriverManager;

public class DbUtil {
// 定义数据库驱动程序
private static final String driver = "com.mysql.jdbc.Driver";
// 数据库连接地址
private static final String url = "jdbc:mysql://localhost:3306/db_courseselect?useUnicode=true&characterEncoding=utf-8";// library表示数据库
private static final String user = "root";
private static final String password = "LWZ222MESSI";
private static Connection connection = null;

    // 连接数据库
    public DbUtil(){
        // 数据库操作可能出现异常
        try {
            Class.forName(driver);
            System.out.println("加载驱动文件成功!");
            connection = DriverManager.getConnection(url, user, password);
            System.out.println("获得连接对象成功!");
        } catch (Exception exception) {
            exception.printStackTrace();
            System.out.println("数据库连接失败");

        } finally {

        }
    }

    public static Connection getConnection() {
        return connection;
    }

    public static void close(Connection connection ) throws Exception {
        if (connection != null) {
            try {
                connection.close();
            } catch (Exception e) {
                // TODO: handle exception
                throw e;
            }
        }
    }

}

5个回答

u011892089
u011892089   2016.09.09 08:40

你这个默认开启了SSL连接,“You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.”应该在数据库中设置 useSSL=false就可以了。

zihan11201120
zihan11201120   2016.09.09 13:06

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) 错误在这里! 在user表里面新增数据
如果是远程你的ip为192.168.1.89 则为
CREATE USER 'root'@'192.168.1.89' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON . TO root@'192.168.1.89';
或参考
http://www.javaweb1024.com/info/985.jspx

u013829202
u013829202   Rxr 2016.09.09 15:37

这个错误其实对运行项目没影响才对吧。 他是意思是你安装了mysql,但是没有修改mysql的密码。 修改下root的密码就好了。

Marksinoberg
Marksinoberg   Ds   Rxr 2016.09.09 17:21
 For compliance with existing applications not using SSL the verifyServerCertificate 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 verification.

进行修改即可。

gulamali
gulamali   2016.09.09 17:42

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) 错误在这里! 在user表里面新增数据
如果是远程你的ip为192.168.1.89 则为
CREATE USER 'root'@'192.168.1.89' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON . TO root@'192.168.1.89';
或参考
http://www.javaweb1024.com/info/985.jspx

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
java连接MySQL数据库时常见故障问题的分析与解决
初学的mysql经常会碰到mysql无法连接的错误。收集的这样问题的现象和原因。   先自己扔块砖头出来。   归纳如下: 更改mysql root账号密码 mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass'); 故障现象 : 无法连接 mysql   ===================
java连接mysql的方法及问题解决方案
java连接mysql数据库简单操作
Java链接Mysql中文问号乱码解决办法
最近写爬虫,准备把数据存到 数据库,但是一直出现 '?'乱码的情况,试了好多种方法,我是总结出只要有以下2种配置就不会出现乱码了。 1.  需要在配置文件 my.ini 中加上默认字符编码为utf8: default-character-set=utf8 [mysql] no-auto-rehash ; Remove the next comment character i
解决Java连接MySQL数据库,中文显示乱码问题
有效解决Java的JDBC连接远程Mysql中文乱码的问题!!!
java调用mysql获取不到连接的问题
之前做了一个web项目的时候,好好的网站第二天总是会提示using the Connector/J connection property 'autoReconnect=true' to avoid this problem.  这样的错误 com.mysql.jdbc.CommunicationsException: The last packet successfully received
java连接网络SQLSERVER2000主法及错误处理
JAVA 连SQLSERVER容易出现的问题及连接网络数据库时如何用机器名连接的问题 。
JDBC连接MySQL字符集错误解决办法
JDBC连接MySQL字符集错误解决办法:   在进行Java中JDBC连接到MySQL数据库时,大多数人都会碰到中文乱码问题,实际上是MySQL中字符集的设置问题。通过对网上资源的整理再分析,并结合我个人的经验,下面对JDBC连接到MySQL数据库时出现的乱码问题进行解释与分析: *注: 1、 笔者用的是Eclipse 连接MySQL 数据库,数据库软件(图形化工具)Navicat,电脑
java无法连接高版本mysql数据库问题
转自链接:https://zhidao.baidu.com/question/2056521203295428667.html Java使用mysql-jdbc连接MySQL出现如下警告:  Establishing SSL connection without server's identity verification is not recommended. According to MyS
Java使用mysql-jdbc连接MySQL出现如下警告:
Java使用mysql-jdbc连接MySQL出现如下警告: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6
java web JBDC mysql一直加载不到驱动的解决方案
最近两天在自己学习如何配置java的ssm框架(Structs2,spring,mybatis)。 遇到tomcat无法加载mysql-connector驱动类,mysql版本用的5.6.10,jar包使用5.1.39. 系统老是java.lang.ClassNotFoundException: com.mysql.jdbc.Driver确认包已经被导入web工程目...