连接到MySQL数据库时有关SSL连接的警告
通过以下两个类,我尝试连接到MySQL数据库。但是,我总是得到这个错误:Wed Dec 09 22:46:52 CET WARN:不建议在没有服务器身份验证的情况下建立SSL连接。根据MySQL 5.5.45 +,5.6.26 +和5.7.6+要求如果未设置显式选项,则必须默认建立SSL连接。为了符合不使用SSL的现有应用程序,verifyServerCertificate属性设置为“false”。您需要通过设置useSSL = false显式禁用SSL,或者设置useSSL = true并为服务器证书验证提供信任库。
这是使用以下main方法的测试类:publicclassTestDatabase{
publicstaticvoidmain(String[]args){
Databasedb=newDatabase();
try{
db.connect();
}catch(Exceptione){
e.printStackTrace();
}
db.close();
}}
这是Database班级:importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;publicclassDatabase{
privateConnectioncon;
publicvoidconnect()throwsException{
if(con!=null)return;
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundExceptione){
thrownewException("Nodatabase");
}
StringconnectionURL="jdbc:mysql://localhost:3306/Peoples";
con=DriverManager.getConnection(connectionURL,"root","milos23");
}
publicvoidclose(){
if(con!=null){
try{
con.close();
}catch(SQLExceptione){
e.printStackTrace();
}
}
}}