0

Getting this error while connecting to Eclipse with mysql anybody could help.

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.

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database '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();
    }
}

}
3
  • do you have mydb database in mysql? Commented Feb 20, 2018 at 9:37
  • Yes i have mydb in mysql. Commented Feb 20, 2018 at 9:40
  • According to that error, you don't have a database called mydb. So either you are connecting to the wrong server, or the name isn't mydb. Commented Feb 20, 2018 at 9:57

1 Answer 1

2

you need to pass parameter useSSL=true in your mysql url like this:

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

or try with

  Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb?useUnicode=yes&characterEncoding=UTF-8", "root","bilmuj98");
Sign up to request clarification or add additional context in comments.

2 Comments

After adding this line i am getting this error. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'mydb' at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
I have added one more suggestion

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.