import java.sql.*; //导入java.sql包
public class Login {//创建Login类,保证文件名与类名相同
Connection con;//声明Connection对象
Statement sql;
ResultSet res;
public Connection getConnection() { //建立返回值为Connection的方法
try { //加载数据库驱动类
Class.forName("com.mysql.jdbc.Driver");
System.out.println("数据库驱动加载成功");
}catch(ClassNotFoundException e){
e.printStackTrace();
}
try {
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","root");//通过访问数据库的URL获取数据库连接对象
System.out.println("数据库连接成功");
}catch(SQLException e) {
e.printStackTrace();
}
return con;//按方法要求返回一个Connection对象
}
public static void main(String[] args) { //主方法
Login c = new Login(); //创建本类方法
c.getConnection();//调用连接数据库的方法
}
}
运行代码,数据库加载连接成功,但是出现这一行红字,萌新不懂,求大佬指教。
红字内容:Tue Dec 10 14:27:27 CST 2019 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.