使用下面的两个类,我尝试连接到一个mysql数据库。但是,我总是会得到这个错误:
2015年12月9日星期三22:46:52 CET警告:不建议在未经服务器身份验证的情况下建立SSL连接。根据mysql 5.5.45+、5.6.26+和5.7.6+的要求,如果未设置显式选项,则默认情况下必须建立ssl连接。为了符合不使用SSL的现有应用程序,VerifyServerCertificate属性设置为“false”。您需要通过设置usessl=false显式禁用ssl,或者设置usessl=true并为服务器证书验证提供信任存储。
这是一个测试类
main
方法:
public class TestDatabase {
public static void main(String[] args) {
Database db = new Database();
try {
db.connect();
} catch (Exception e) {
e.printStackTrace();
}
db.close();
}
}
这就是
Database
班级:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Database {
private Connection con;
public void connect() throws Exception{
if(con != null) return;
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
throw new Exception("No database");
}
String connectionURL = "jdbc:mysql://localhost:3306/Peoples";
con = DriverManager.getConnection(connectionURL, "root", "milos23");
}
public void close(){
if(con != null){
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}