Eclipse和Mysql连接错误

问题描述 投票:0回答:1

使用mysql连接到Eclipse时出现此错误任何人都可以提供帮助。

建议不要在没有服务器身份验证的情况下建立SSL连接。

根据MySQL 5.5.45 +,5.6.26 +和5.7.6+要求如果未设置显式选项,则必须默认建立SSL连接。为了符合不使用SSL的现有应用程序,verifyServerCertificate属性设置为“false”。您需要通过设置useSSL=false来显式禁用SSL,或者设置useSSL=true并为服务器证书验证提供信任库。

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:未知数据库'mydb'

package jdbcDemo;

import java.sql.*;
public class Driver {

public static void main(String[] args) {
    try{
        //1. Creating Connection to a Database
        Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root","bilmuj98");

        //2. Creating Statement
        Statement myStmt = myConn.createStatement(); 

        //3. Execute SQL Query
        ResultSet myRs = myStmt.executeQuery("Select * from mydb.Employee");

        //4. Process the result set
        while(myRs.next())
        {
            System.out.println(myRs.getString("first_name") + "," + myRs.getString("last_name"));
        }
    }
    catch(Exception exc)
    {   
        exc.printStackTrace();
    }
}

}
java mysql eclipse
1个回答
1
投票

你需要在你的mysql网址中传递参数useSSL=true,如下所示:

 Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb?useSSL=true", "root","bilmuj98");

或试试

  Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb?useUnicode=yes&characterEncoding=UTF-8", "root","bilmuj98");
© www.soinside.com 2019 - 2024. All rights reserved.