SQLException

I started throwing exceptions directly in the main method, but the jvm stopped. I changed the try catch to throw and found that it was a SQLException. I thought it was a problem with the url. Follow the instructions written on the Internet, add wait_timeout, restart, or not.
Insert picture description here
Then let the stack information output Like this,
Insert picture description here
I checked it online and suggested me
Insert picture description here
, but I have added it and checked it again. I suspect that this is the problem.

Insert picture description here
I found myself stupid, mine was configured by ini.
Angrily changed ssl to true, and found that this time it was not the error reported before, only the transport:'socket' was displayed. I searched the Internet. Others were confused, saying that it was just closing other items. After closing it, change it to false, hey, it's out! Insert picture description hereBut I don’t know why there is transport:'socket', and disconnected, continue to refer to
Insert picture description here
and then I turn off the idea, and then turn it on again, okay, world peace,
Insert picture description here
attach the simple code I wrote

import java.sql.*;

public class New {
    
    
    public static void main(String[] args){
    
    
       try {
    
    
           Class.forName("com.mysql.jdbc.Driver");//注册数据库的驱动
           //获取数据库连接
           Connection con = DriverManager.getConnection("jdbc:mysql:/localhost:3506/join?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8", "root", "password");
           //需要执行的sql语句
           String sql = "select * from my_employees";
           //获取预处理对象
           PreparedStatement statement = con.prepareStatement(sql);
           //执行sql语句
           ResultSet resultSet = statement.executeQuery();
           while (resultSet.next()) {
    
    //如果有下一条记录
               String id = resultSet.getString("id");//根据列名返回值
               String First_name = resultSet.getString("First_name");
               String Last_name = resultSet.getString("Last_name");
               String Userid = resultSet.getString("Userid");
               int Salary = resultSet.getInt(5);//根据列的顺序返回值
               System.out.println(id + "\t" + First_name + "\t" + Last_name + "\t" + "Userid" + "\t" + "Salary");

           }
           //关闭jdbc连接;
           resultSet.close();
           statement.close();
           con.close();
       }catch ( ClassNotFoundException e)
       {
    
    
           System.out.println("1");

       }catch (SQLException e)
       {
    
    
           System.out.println("2");
        e.getStackTrace();
       }
    }

}

Thank you for helping me and the following link:
https://blog.csdn.net/a704397849/article/details/89378931
https://www.cnblogs.com/hafiz/p/5879432.html

Guess you like

Origin blog.csdn.net/weixin_46064382/article/details/106676622