java连接数据库时的报错
//java连接数据库时的报错
1 package Java数据库编程; 2 3 import java.sql.DriverManager; 4 import java.sql.SQLException; 5 6 import com.mysql.jdbc.Connection; 7 8 public class ConnectionDemo202 { 9 // 定义MySQL的数据库程序驱动 10 public static final String DRIVER = "org.gjt.mm.mysql.Driver"; 11 // 定义MySQL的数据库的连接地址 12 public static final String DBURL = "jdbc:mysql://localhost:3306/supermark"; 13 // 定义MySQL的数据库用名 14 public static final String DBUSER = "root"; 15 // 定义MySQL的数据库密码 16 public static final String DBPASS = "123456"; 17 18 public static void main(String[] args) { 19 20 Connection conn = null; 21 try { 22 23 Class.forName(DRIVER); // 加载驱动程序 24 } catch (ClassNotFoundException e) { 25 // TODO 自动生成的 catch 块 26 e.printStackTrace(); 27 } 28 try { 29 // 连接MySQL数据库, 30 conn = (Connection) DriverManager.getConnection(DBURL, DBUSER, DBPASS); 31 } catch (SQLException e) { 32 // TODO 自动生成的 catch 块 33 e.printStackTrace(); 34 } 35 try { 36 // 关闭数据库 37 conn.close(); 38 } catch (SQLException e) { 39 // TODO 自动生成的 catch 块 40 e.printStackTrace(); 41 } 42 } 43 }
运行结果是:
Mon Jul 03 11:20:41 CST 2017 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.
出现这样的情况,根据系统的报错,MySQL 5.5.45 + 5.6.26 +和5.7.6 +要求必须建立SSL连接默认情况下如果不设置明确的选项。我们只需要在
定义MySQL的数据库的连接地址
public static final String DBURL = "jdbc:mysql://localhost:3306/supermark";的后面的数据库名的后面加多?useSSL=false即可
新手出门,如哪里出错,还望指出。