RONALDO12 2016-09-08 17:13 采纳率: 0%
浏览 2458

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条回答

  • llxiaoh 2016-09-09 00: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就可以了。

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog