If you are running MySQL 5.7.x and Netbeans 8.1 and you come across this warning,
1. MySQL 5.7.x (Actually its a good feature but really annoying to new users)
2. MySQL Java Connector Jar File
Solution for Culprit 1:
If your traditional code for JDBC is like:
So the modified code is:
You will find that we have appended [+dbname+"?autoReconnect=true&useSSL=false" ] to the part after URL of database.
Example:
Solution for Culprit 2:
Change the driver version of mysql connector other than 5.1.39. I have checked for 5.1.38,5.1.36.
Just use these versions and you program will be free from warning.
I have tested this with Eclipse also.
Hope this will help you !
"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."Don't worry! The culprits are:
1. MySQL 5.7.x (Actually its a good feature but really annoying to new users)
2. MySQL Java Connector Jar File
Solution for Culprit 1:
If your traditional code for JDBC is like:
/*
* To make java and mysql connectivity
*/
package com.java.databases;
import java.sql.*;
/**
*
* @author mayur
*/
public class Java2MySQL {
public static void main(String[] args) {
String dbname = "ram_db";
String uname = "root";
String passw = "ramayan";
String url = "jdbc:mysql://localhost:3306/";
String driver = "com.mysql.jdbc.Driver";
try {
Class.forName(driver);
System.out.println("Connection is Registered");
Connection conn = DriverManager.getConnection(url+dbname, uname, passw);
System.out.println("Connection is Open");
conn.close();
System.out.println("Connection is closed");
} catch (Exception e) {
System.err.println("Something is wrong!! Please wait while we fix it");// e.printStackTrace();//(Something is wrong!! Please wait while we fix it);
}
}
}
So the modified code is:
/*
* To make java and mysql connectivity
*/
package com.java.databases;
import java.sql.*;
/**
*
* @author mayur
*/
public class Java2MySQL {
public static void main(String[] args) {
String dbname = "don_db";
String uname = "root";
String passw = "";
String url = "jdbc:mysql://localhost:3306/"+dbname+"?autoReconnect=true&useSSL=false";
String driver = "com.mysql.jdbc.Driver";
try {
Class.forName(driver);
System.out.println("Connection is Registered");
Connection conn = DriverManager.getConnection(url, uname, passw);
System.out.println("Connection is Open");
conn.close();
System.out.println("Connection is closed");
} catch (Exception e) {
System.err.println("Something is wrong!! Please wait while we fix it");// e.printStackTrace();//(Something is wrong!! Please wait while we fix it);
}
}
}
You will find that we have appended [+dbname+"?autoReconnect=true&useSSL=false" ] to the part after URL of database.
Example:
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost:3306/"+dbname+"?autoReconnect=true&useSSL=false","root","");
Solution for Culprit 2:
Change the driver version of mysql connector other than 5.1.39. I have checked for 5.1.38,5.1.36.
Just use these versions and you program will be free from warning.
I have tested this with Eclipse also.
Hope this will help you !
Thank you sharing the excellent post about JAVA programming. you helped me to gain more information on the JAVA language.
ReplyDeletejava j2ee training
core java training in chennai
my pleasure.
Delete