[JavaEE]连接数据库遇到的问题

 

问题1:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

 

需要导入mysql的jar包,我是ubuntu的系统

进入mysql官网    https://dev.mysql.com/downloads

[JavaEE]连接数据库遇到的问题

 

 

 

然后点击connector J

[JavaEE]连接数据库遇到的问题

windows下载zip,ubuntu下载tar.gz,但是根据电脑系统选择的Ubuntu只有deb,所以要点击旁边的“Looking for previous GA versions?”,然后进行下载

 

下载后解压
sudo tar -zxvf ......

 

然后将文件中的bin.jar后缀名的jar包移动到eclipse里你存储代码的位置

[JavaEE]连接数据库遇到的问题

 

[JavaEE]连接数据库遇到的问题

如图移动。

 

 

点击右键然后Build Path, 然后选择add....然后即可

[JavaEE]连接数据库遇到的问题

 

Referenced Libraries中有这个mysql ...bin.jar,这样就完成了

 

 

 

 

问题2:

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.

 

没有设置SSL,修改JDBC连接的url

初始:
final static String url = "jdbc:mysql://localhost:3306/SuperBookData";

在后面+上“?useUnicode=true&characterEncoding=utf-8&useSSL=false”
修改为: final static String url = "jdbc:mysql://localhost:3306/SuperBookData?useUnicode=true&characterEncoding=utf-8&useSSL=false";

 

上一篇:Access denied for user ''@'192.168.1.11' (using password: NO)之idea坑~


下一篇:mysql 驱动包