Reputation: 37
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();
}
}
}
Upvotes: 0
Views: 2320
Reputation: 4518
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");
Upvotes: 1