package com.JDBC;
import java.sql.*;
public class Jdbc {
public static void main(String[] args) throws Exception
{
String URL = "jdbc:mysql://localhost:3306/test1";
String USER = "root";
String PASSWORD = "12345";
//1加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
//2获得数据库的连接
Connection c1 = DriverManager.getConnection(URL, USER, PASSWORD);
//3 操作数据库
Statement s1= c1.createStatement();
ResultSet r1 = s1.executeQuery("select id from my");
while(r1.next())
{
System.out.println(r1.getString("id"));
}
}
import java.sql.*;
public class Jdbc {
public static void main(String[] args) throws Exception
{
String URL = "jdbc:mysql://localhost:3306/test1";
String USER = "root";
String PASSWORD = "12345";
//1加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
//2获得数据库的连接
Connection c1 = DriverManager.getConnection(URL, USER, PASSWORD);
//3 操作数据库
Statement s1= c1.createStatement();
ResultSet r1 = s1.executeQuery("select id from my");
while(r1.next())
{
System.out.println(r1.getString("id"));
}
}
}
这样运行会显示连接错误WARN: Establishing SSL connection without server's identity verification is...
解决办法:1、在url后面添加useSSL=false或useSSL=true
改成 String URL = "jdbc:mysql://localhost:3306/test1?useSSL=false";