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 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题