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就可以了。

    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败